ide.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  1. /*
  2. * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
  3. * Copyrifht (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz
  4. */
  5. /*
  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>
  9. *
  10. * See linux/MAINTAINERS for address of current maintainer.
  11. *
  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
  14. * (usually 14 & 15).
  15. * There can be up to two drives per interface, as per the ATA-2 spec.
  16. *
  17. * ...
  18. *
  19. * From hd.c:
  20. * |
  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!
  24. * |
  25. * | modified by Drew Eckhardt to check nr of hd's from the CMOS.
  26. * |
  27. * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
  28. * | in the early extended-partition checks and added DM partitions.
  29. * |
  30. * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
  31. * |
  32. * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
  33. * | and general streamlining by Mark Lord (mlord@pobox.com).
  34. *
  35. * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
  36. *
  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)
  40. *
  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
  44. */
  45. #define _IDE_C /* Tell ide.h it's really us */
  46. #include <linux/module.h>
  47. #include <linux/types.h>
  48. #include <linux/string.h>
  49. #include <linux/kernel.h>
  50. #include <linux/timer.h>
  51. #include <linux/mm.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/major.h>
  54. #include <linux/errno.h>
  55. #include <linux/genhd.h>
  56. #include <linux/blkpg.h>
  57. #include <linux/slab.h>
  58. #include <linux/init.h>
  59. #include <linux/pci.h>
  60. #include <linux/delay.h>
  61. #include <linux/ide.h>
  62. #include <linux/completion.h>
  63. #include <linux/reboot.h>
  64. #include <linux/cdrom.h>
  65. #include <linux/seq_file.h>
  66. #include <linux/device.h>
  67. #include <linux/bitops.h>
  68. #include <asm/byteorder.h>
  69. #include <asm/irq.h>
  70. #include <asm/uaccess.h>
  71. #include <asm/io.h>
  72. /* default maximum number of failures */
  73. #define IDE_DEFAULT_MAX_FAILURES 1
  74. struct class *ide_port_class;
  75. static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
  76. IDE2_MAJOR, IDE3_MAJOR,
  77. IDE4_MAJOR, IDE5_MAJOR,
  78. IDE6_MAJOR, IDE7_MAJOR,
  79. IDE8_MAJOR, IDE9_MAJOR };
  80. static int idebus_parameter; /* holds the "idebus=" parameter */
  81. static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */
  82. DEFINE_MUTEX(ide_cfg_mtx);
  83. __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
  84. int noautodma = 0;
  85. #ifdef CONFIG_BLK_DEV_IDEACPI
  86. int ide_noacpi = 0;
  87. int ide_noacpitfs = 1;
  88. int ide_noacpionboot = 1;
  89. #endif
  90. ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
  91. static void ide_port_init_devices_data(ide_hwif_t *);
  92. /*
  93. * Do not even *think* about calling this!
  94. */
  95. void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
  96. {
  97. /* bulk initialize hwif & drive info with zeros */
  98. memset(hwif, 0, sizeof(ide_hwif_t));
  99. /* fill in any non-zero initial values */
  100. hwif->index = index;
  101. hwif->major = ide_hwif_to_major[index];
  102. hwif->name[0] = 'i';
  103. hwif->name[1] = 'd';
  104. hwif->name[2] = 'e';
  105. hwif->name[3] = '0' + index;
  106. hwif->bus_state = BUSSTATE_ON;
  107. init_completion(&hwif->gendev_rel_comp);
  108. default_hwif_iops(hwif);
  109. default_hwif_transport(hwif);
  110. ide_port_init_devices_data(hwif);
  111. }
  112. EXPORT_SYMBOL_GPL(ide_init_port_data);
  113. static void ide_port_init_devices_data(ide_hwif_t *hwif)
  114. {
  115. int unit;
  116. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  117. ide_drive_t *drive = &hwif->drives[unit];
  118. u8 j = (hwif->index * MAX_DRIVES) + unit;
  119. memset(drive, 0, sizeof(*drive));
  120. drive->media = ide_disk;
  121. drive->select.all = (unit<<4)|0xa0;
  122. drive->hwif = hwif;
  123. drive->ctl = 0x08;
  124. drive->ready_stat = READY_STAT;
  125. drive->bad_wstat = BAD_W_STAT;
  126. drive->special.b.recalibrate = 1;
  127. drive->special.b.set_geometry = 1;
  128. drive->name[0] = 'h';
  129. drive->name[1] = 'd';
  130. drive->name[2] = 'a' + j;
  131. drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
  132. INIT_LIST_HEAD(&drive->list);
  133. init_completion(&drive->gendev_rel_comp);
  134. }
  135. }
  136. /*
  137. * init_ide_data() sets reasonable default values into all fields
  138. * of all instances of the hwifs and drives, but only on the first call.
  139. * Subsequent calls have no effect (they don't wipe out anything).
  140. *
  141. * This routine is normally called at driver initialization time,
  142. * but may also be called MUCH earlier during kernel "command-line"
  143. * parameter processing. As such, we cannot depend on any other parts
  144. * of the kernel (such as memory allocation) to be functioning yet.
  145. *
  146. * This is too bad, as otherwise we could dynamically allocate the
  147. * ide_drive_t structs as needed, rather than always consuming memory
  148. * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
  149. *
  150. * FIXME: We should stuff the setup data into __init and copy the
  151. * relevant hwifs/allocate them properly during boot.
  152. */
  153. #define MAGIC_COOKIE 0x12345678
  154. static void __init init_ide_data (void)
  155. {
  156. unsigned int index;
  157. static unsigned long magic_cookie = MAGIC_COOKIE;
  158. if (magic_cookie != MAGIC_COOKIE)
  159. return; /* already initialized */
  160. magic_cookie = 0;
  161. /* Initialise all interface structures */
  162. for (index = 0; index < MAX_HWIFS; ++index) {
  163. ide_hwif_t *hwif = &ide_hwifs[index];
  164. ide_init_port_data(hwif, index);
  165. }
  166. }
  167. /**
  168. * ide_system_bus_speed - guess bus speed
  169. *
  170. * ide_system_bus_speed() returns what we think is the system VESA/PCI
  171. * bus speed (in MHz). This is used for calculating interface PIO timings.
  172. * The default is 40 for known PCI systems, 50 otherwise.
  173. * The "idebus=xx" parameter can be used to override this value.
  174. * The actual value to be used is computed/displayed the first time
  175. * through. Drivers should only use this as a last resort.
  176. *
  177. * Returns a guessed speed in MHz.
  178. */
  179. static int ide_system_bus_speed(void)
  180. {
  181. #ifdef CONFIG_PCI
  182. static struct pci_device_id pci_default[] = {
  183. { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) },
  184. { }
  185. };
  186. #else
  187. #define pci_default 0
  188. #endif /* CONFIG_PCI */
  189. /* user supplied value */
  190. if (idebus_parameter)
  191. return idebus_parameter;
  192. /* safe default value for PCI or VESA and PCI*/
  193. return pci_dev_present(pci_default) ? 33 : 50;
  194. }
  195. void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
  196. {
  197. ide_hwgroup_t *hwgroup = hwif->hwgroup;
  198. spin_lock_irq(&ide_lock);
  199. /*
  200. * Remove us from the hwgroup, and free
  201. * the hwgroup if we were the only member
  202. */
  203. if (hwif->next == hwif) {
  204. BUG_ON(hwgroup->hwif != hwif);
  205. kfree(hwgroup);
  206. } else {
  207. /* There is another interface in hwgroup.
  208. * Unlink us, and set hwgroup->drive and ->hwif to
  209. * something sane.
  210. */
  211. ide_hwif_t *g = hwgroup->hwif;
  212. while (g->next != hwif)
  213. g = g->next;
  214. g->next = hwif->next;
  215. if (hwgroup->hwif == hwif) {
  216. /* Chose a random hwif for hwgroup->hwif.
  217. * It's guaranteed that there are no drives
  218. * left in the hwgroup.
  219. */
  220. BUG_ON(hwgroup->drive != NULL);
  221. hwgroup->hwif = g;
  222. }
  223. BUG_ON(hwgroup->hwif == hwif);
  224. }
  225. spin_unlock_irq(&ide_lock);
  226. }
  227. /* Called with ide_lock held. */
  228. static void __ide_port_unregister_devices(ide_hwif_t *hwif)
  229. {
  230. int i;
  231. for (i = 0; i < MAX_DRIVES; i++) {
  232. ide_drive_t *drive = &hwif->drives[i];
  233. if (drive->present) {
  234. spin_unlock_irq(&ide_lock);
  235. device_unregister(&drive->gendev);
  236. wait_for_completion(&drive->gendev_rel_comp);
  237. spin_lock_irq(&ide_lock);
  238. }
  239. }
  240. }
  241. void ide_port_unregister_devices(ide_hwif_t *hwif)
  242. {
  243. mutex_lock(&ide_cfg_mtx);
  244. spin_lock_irq(&ide_lock);
  245. __ide_port_unregister_devices(hwif);
  246. hwif->present = 0;
  247. ide_port_init_devices_data(hwif);
  248. spin_unlock_irq(&ide_lock);
  249. mutex_unlock(&ide_cfg_mtx);
  250. }
  251. EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
  252. /**
  253. * ide_unregister - free an IDE interface
  254. * @index: index of interface (will change soon to a pointer)
  255. *
  256. * Perform the final unregister of an IDE interface. At the moment
  257. * we don't refcount interfaces so this will also get split up.
  258. *
  259. * Locking:
  260. * The caller must not hold the IDE locks
  261. * The drive present/vanishing is not yet properly locked
  262. * Take care with the callbacks. These have been split to avoid
  263. * deadlocking the IDE layer. The shutdown callback is called
  264. * before we take the lock and free resources. It is up to the
  265. * caller to be sure there is no pending I/O here, and that
  266. * the interface will not be reopened (present/vanishing locking
  267. * isn't yet done BTW). After we commit to the final kill we
  268. * call the cleanup callback with the ide locks held.
  269. *
  270. * Unregister restores the hwif structures to the default state.
  271. * This is raving bonkers.
  272. */
  273. void ide_unregister(unsigned int index)
  274. {
  275. ide_hwif_t *hwif, *g;
  276. ide_hwgroup_t *hwgroup;
  277. int irq_count = 0;
  278. BUG_ON(index >= MAX_HWIFS);
  279. BUG_ON(in_interrupt());
  280. BUG_ON(irqs_disabled());
  281. mutex_lock(&ide_cfg_mtx);
  282. spin_lock_irq(&ide_lock);
  283. hwif = &ide_hwifs[index];
  284. if (!hwif->present)
  285. goto abort;
  286. __ide_port_unregister_devices(hwif);
  287. hwif->present = 0;
  288. spin_unlock_irq(&ide_lock);
  289. ide_proc_unregister_port(hwif);
  290. hwgroup = hwif->hwgroup;
  291. /*
  292. * free the irq if we were the only hwif using it
  293. */
  294. g = hwgroup->hwif;
  295. do {
  296. if (g->irq == hwif->irq)
  297. ++irq_count;
  298. g = g->next;
  299. } while (g != hwgroup->hwif);
  300. if (irq_count == 1)
  301. free_irq(hwif->irq, hwgroup);
  302. ide_remove_port_from_hwgroup(hwif);
  303. device_unregister(hwif->portdev);
  304. device_unregister(&hwif->gendev);
  305. wait_for_completion(&hwif->gendev_rel_comp);
  306. /*
  307. * Remove us from the kernel's knowledge
  308. */
  309. blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
  310. kfree(hwif->sg_table);
  311. unregister_blkdev(hwif->major, hwif->name);
  312. spin_lock_irq(&ide_lock);
  313. if (hwif->dma_base)
  314. ide_release_dma_engine(hwif);
  315. /* restore hwif data to pristine status */
  316. ide_init_port_data(hwif, index);
  317. abort:
  318. spin_unlock_irq(&ide_lock);
  319. mutex_unlock(&ide_cfg_mtx);
  320. }
  321. EXPORT_SYMBOL(ide_unregister);
  322. void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
  323. {
  324. memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
  325. hwif->irq = hw->irq;
  326. hwif->chipset = hw->chipset;
  327. hwif->gendev.parent = hw->dev;
  328. hwif->ack_intr = hw->ack_intr;
  329. }
  330. EXPORT_SYMBOL_GPL(ide_init_port_hw);
  331. /*
  332. * Locks for IDE setting functionality
  333. */
  334. DEFINE_MUTEX(ide_setting_mtx);
  335. EXPORT_SYMBOL_GPL(ide_setting_mtx);
  336. /**
  337. * ide_spin_wait_hwgroup - wait for group
  338. * @drive: drive in the group
  339. *
  340. * Wait for an IDE device group to go non busy and then return
  341. * holding the ide_lock which guards the hwgroup->busy status
  342. * and right to use it.
  343. */
  344. int ide_spin_wait_hwgroup (ide_drive_t *drive)
  345. {
  346. ide_hwgroup_t *hwgroup = HWGROUP(drive);
  347. unsigned long timeout = jiffies + (3 * HZ);
  348. spin_lock_irq(&ide_lock);
  349. while (hwgroup->busy) {
  350. unsigned long lflags;
  351. spin_unlock_irq(&ide_lock);
  352. local_irq_set(lflags);
  353. if (time_after(jiffies, timeout)) {
  354. local_irq_restore(lflags);
  355. printk(KERN_ERR "%s: channel busy\n", drive->name);
  356. return -EBUSY;
  357. }
  358. local_irq_restore(lflags);
  359. spin_lock_irq(&ide_lock);
  360. }
  361. return 0;
  362. }
  363. EXPORT_SYMBOL(ide_spin_wait_hwgroup);
  364. int set_io_32bit(ide_drive_t *drive, int arg)
  365. {
  366. if (drive->no_io_32bit)
  367. return -EPERM;
  368. if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
  369. return -EINVAL;
  370. if (ide_spin_wait_hwgroup(drive))
  371. return -EBUSY;
  372. drive->io_32bit = arg;
  373. spin_unlock_irq(&ide_lock);
  374. return 0;
  375. }
  376. static int set_ksettings(ide_drive_t *drive, int arg)
  377. {
  378. if (arg < 0 || arg > 1)
  379. return -EINVAL;
  380. if (ide_spin_wait_hwgroup(drive))
  381. return -EBUSY;
  382. drive->keep_settings = arg;
  383. spin_unlock_irq(&ide_lock);
  384. return 0;
  385. }
  386. int set_using_dma(ide_drive_t *drive, int arg)
  387. {
  388. #ifdef CONFIG_BLK_DEV_IDEDMA
  389. ide_hwif_t *hwif = drive->hwif;
  390. int err = -EPERM;
  391. if (arg < 0 || arg > 1)
  392. return -EINVAL;
  393. if (!drive->id || !(drive->id->capability & 1))
  394. goto out;
  395. if (hwif->dma_ops == NULL)
  396. goto out;
  397. err = -EBUSY;
  398. if (ide_spin_wait_hwgroup(drive))
  399. goto out;
  400. /*
  401. * set ->busy flag, unlock and let it ride
  402. */
  403. hwif->hwgroup->busy = 1;
  404. spin_unlock_irq(&ide_lock);
  405. err = 0;
  406. if (arg) {
  407. if (ide_set_dma(drive))
  408. err = -EIO;
  409. } else
  410. ide_dma_off(drive);
  411. /*
  412. * lock, clear ->busy flag and unlock before leaving
  413. */
  414. spin_lock_irq(&ide_lock);
  415. hwif->hwgroup->busy = 0;
  416. spin_unlock_irq(&ide_lock);
  417. out:
  418. return err;
  419. #else
  420. if (arg < 0 || arg > 1)
  421. return -EINVAL;
  422. return -EPERM;
  423. #endif
  424. }
  425. int set_pio_mode(ide_drive_t *drive, int arg)
  426. {
  427. struct request rq;
  428. ide_hwif_t *hwif = drive->hwif;
  429. const struct ide_port_ops *port_ops = hwif->port_ops;
  430. if (arg < 0 || arg > 255)
  431. return -EINVAL;
  432. if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
  433. (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
  434. return -ENOSYS;
  435. if (drive->special.b.set_tune)
  436. return -EBUSY;
  437. ide_init_drive_cmd(&rq);
  438. rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
  439. drive->tune_req = (u8) arg;
  440. drive->special.b.set_tune = 1;
  441. (void) ide_do_drive_cmd(drive, &rq, ide_wait);
  442. return 0;
  443. }
  444. static int set_unmaskirq(ide_drive_t *drive, int arg)
  445. {
  446. if (drive->no_unmask)
  447. return -EPERM;
  448. if (arg < 0 || arg > 1)
  449. return -EINVAL;
  450. if (ide_spin_wait_hwgroup(drive))
  451. return -EBUSY;
  452. drive->unmask = arg;
  453. spin_unlock_irq(&ide_lock);
  454. return 0;
  455. }
  456. /**
  457. * system_bus_clock - clock guess
  458. *
  459. * External version of the bus clock guess used by very old IDE drivers
  460. * for things like VLB timings. Should not be used.
  461. */
  462. int system_bus_clock (void)
  463. {
  464. return system_bus_speed;
  465. }
  466. EXPORT_SYMBOL(system_bus_clock);
  467. static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
  468. {
  469. ide_drive_t *drive = dev->driver_data;
  470. ide_hwif_t *hwif = HWIF(drive);
  471. struct request rq;
  472. struct request_pm_state rqpm;
  473. ide_task_t args;
  474. int ret;
  475. /* Call ACPI _GTM only once */
  476. if (!(drive->dn % 2))
  477. ide_acpi_get_timing(hwif);
  478. memset(&rq, 0, sizeof(rq));
  479. memset(&rqpm, 0, sizeof(rqpm));
  480. memset(&args, 0, sizeof(args));
  481. rq.cmd_type = REQ_TYPE_PM_SUSPEND;
  482. rq.special = &args;
  483. rq.data = &rqpm;
  484. rqpm.pm_step = ide_pm_state_start_suspend;
  485. if (mesg.event == PM_EVENT_PRETHAW)
  486. mesg.event = PM_EVENT_FREEZE;
  487. rqpm.pm_state = mesg.event;
  488. ret = ide_do_drive_cmd(drive, &rq, ide_wait);
  489. /* only call ACPI _PS3 after both drivers are suspended */
  490. if (!ret && (((drive->dn % 2) && hwif->drives[0].present
  491. && hwif->drives[1].present)
  492. || !hwif->drives[0].present
  493. || !hwif->drives[1].present))
  494. ide_acpi_set_state(hwif, 0);
  495. return ret;
  496. }
  497. static int generic_ide_resume(struct device *dev)
  498. {
  499. ide_drive_t *drive = dev->driver_data;
  500. ide_hwif_t *hwif = HWIF(drive);
  501. struct request rq;
  502. struct request_pm_state rqpm;
  503. ide_task_t args;
  504. int err;
  505. /* Call ACPI _STM only once */
  506. if (!(drive->dn % 2)) {
  507. ide_acpi_set_state(hwif, 1);
  508. ide_acpi_push_timing(hwif);
  509. }
  510. ide_acpi_exec_tfs(drive);
  511. memset(&rq, 0, sizeof(rq));
  512. memset(&rqpm, 0, sizeof(rqpm));
  513. memset(&args, 0, sizeof(args));
  514. rq.cmd_type = REQ_TYPE_PM_RESUME;
  515. rq.special = &args;
  516. rq.data = &rqpm;
  517. rqpm.pm_step = ide_pm_state_start_resume;
  518. rqpm.pm_state = PM_EVENT_ON;
  519. err = ide_do_drive_cmd(drive, &rq, ide_head_wait);
  520. if (err == 0 && dev->driver) {
  521. ide_driver_t *drv = to_ide_driver(dev->driver);
  522. if (drv->resume)
  523. drv->resume(drive);
  524. }
  525. return err;
  526. }
  527. int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
  528. unsigned int cmd, unsigned long arg)
  529. {
  530. unsigned long flags;
  531. ide_driver_t *drv;
  532. void __user *p = (void __user *)arg;
  533. int err = 0, (*setfunc)(ide_drive_t *, int);
  534. u8 *val;
  535. switch (cmd) {
  536. case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val;
  537. case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
  538. case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val;
  539. case HDIO_GET_DMA: val = &drive->using_dma; goto read_val;
  540. case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val;
  541. case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val;
  542. case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val;
  543. case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val;
  544. case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val;
  545. }
  546. switch (cmd) {
  547. case HDIO_OBSOLETE_IDENTITY:
  548. case HDIO_GET_IDENTITY:
  549. if (bdev != bdev->bd_contains)
  550. return -EINVAL;
  551. if (drive->id_read == 0)
  552. return -ENOMSG;
  553. if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
  554. return -EFAULT;
  555. return 0;
  556. case HDIO_GET_NICE:
  557. return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
  558. drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
  559. drive->nice1 << IDE_NICE_1,
  560. (long __user *) arg);
  561. #ifdef CONFIG_IDE_TASK_IOCTL
  562. case HDIO_DRIVE_TASKFILE:
  563. if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
  564. return -EACCES;
  565. switch(drive->media) {
  566. case ide_disk:
  567. return ide_taskfile_ioctl(drive, cmd, arg);
  568. default:
  569. return -ENOMSG;
  570. }
  571. #endif /* CONFIG_IDE_TASK_IOCTL */
  572. case HDIO_DRIVE_CMD:
  573. if (!capable(CAP_SYS_RAWIO))
  574. return -EACCES;
  575. return ide_cmd_ioctl(drive, cmd, arg);
  576. case HDIO_DRIVE_TASK:
  577. if (!capable(CAP_SYS_RAWIO))
  578. return -EACCES;
  579. return ide_task_ioctl(drive, cmd, arg);
  580. case HDIO_SET_NICE:
  581. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  582. if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
  583. return -EPERM;
  584. drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
  585. drv = *(ide_driver_t **)bdev->bd_disk->private_data;
  586. if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
  587. drive->dsc_overlap = 0;
  588. return -EPERM;
  589. }
  590. drive->nice1 = (arg >> IDE_NICE_1) & 1;
  591. return 0;
  592. case HDIO_DRIVE_RESET:
  593. if (!capable(CAP_SYS_ADMIN))
  594. return -EACCES;
  595. /*
  596. * Abort the current command on the
  597. * group if there is one, taking
  598. * care not to allow anything else
  599. * to be queued and to die on the
  600. * spot if we miss one somehow
  601. */
  602. spin_lock_irqsave(&ide_lock, flags);
  603. if (HWGROUP(drive)->resetting) {
  604. spin_unlock_irqrestore(&ide_lock, flags);
  605. return -EBUSY;
  606. }
  607. ide_abort(drive, "drive reset");
  608. BUG_ON(HWGROUP(drive)->handler);
  609. /* Ensure nothing gets queued after we
  610. drop the lock. Reset will clear the busy */
  611. HWGROUP(drive)->busy = 1;
  612. spin_unlock_irqrestore(&ide_lock, flags);
  613. (void) ide_do_reset(drive);
  614. return 0;
  615. case HDIO_GET_BUSSTATE:
  616. if (!capable(CAP_SYS_ADMIN))
  617. return -EACCES;
  618. if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
  619. return -EFAULT;
  620. return 0;
  621. case HDIO_SET_BUSSTATE:
  622. if (!capable(CAP_SYS_ADMIN))
  623. return -EACCES;
  624. return -EOPNOTSUPP;
  625. default:
  626. return -EINVAL;
  627. }
  628. read_val:
  629. mutex_lock(&ide_setting_mtx);
  630. spin_lock_irqsave(&ide_lock, flags);
  631. err = *val;
  632. spin_unlock_irqrestore(&ide_lock, flags);
  633. mutex_unlock(&ide_setting_mtx);
  634. return err >= 0 ? put_user(err, (long __user *)arg) : err;
  635. set_val:
  636. if (bdev != bdev->bd_contains)
  637. err = -EINVAL;
  638. else {
  639. if (!capable(CAP_SYS_ADMIN))
  640. err = -EACCES;
  641. else {
  642. mutex_lock(&ide_setting_mtx);
  643. err = setfunc(drive, arg);
  644. mutex_unlock(&ide_setting_mtx);
  645. }
  646. }
  647. return err;
  648. }
  649. EXPORT_SYMBOL(generic_ide_ioctl);
  650. /*
  651. * stridx() returns the offset of c within s,
  652. * or -1 if c is '\0' or not found within s.
  653. */
  654. static int __init stridx (const char *s, char c)
  655. {
  656. char *i = strchr(s, c);
  657. return (i && c) ? i - s : -1;
  658. }
  659. /*
  660. * match_parm() does parsing for ide_setup():
  661. *
  662. * 1. the first char of s must be '='.
  663. * 2. if the remainder matches one of the supplied keywords,
  664. * the index (1 based) of the keyword is negated and returned.
  665. * 3. if the remainder is a series of no more than max_vals numbers
  666. * separated by commas, the numbers are saved in vals[] and a
  667. * count of how many were saved is returned. Base10 is assumed,
  668. * and base16 is allowed when prefixed with "0x".
  669. * 4. otherwise, zero is returned.
  670. */
  671. static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
  672. {
  673. static const char *decimal = "0123456789";
  674. static const char *hex = "0123456789abcdef";
  675. int i, n;
  676. if (*s++ == '=') {
  677. /*
  678. * Try matching against the supplied keywords,
  679. * and return -(index+1) if we match one
  680. */
  681. if (keywords != NULL) {
  682. for (i = 0; *keywords != NULL; ++i) {
  683. if (!strcmp(s, *keywords++))
  684. return -(i+1);
  685. }
  686. }
  687. /*
  688. * Look for a series of no more than "max_vals"
  689. * numeric values separated by commas, in base10,
  690. * or base16 when prefixed with "0x".
  691. * Return a count of how many were found.
  692. */
  693. for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
  694. vals[n] = i;
  695. while ((i = stridx(decimal, *++s)) >= 0)
  696. vals[n] = (vals[n] * 10) + i;
  697. if (*s == 'x' && !vals[n]) {
  698. while ((i = stridx(hex, *++s)) >= 0)
  699. vals[n] = (vals[n] * 0x10) + i;
  700. }
  701. if (++n == max_vals)
  702. break;
  703. if (*s == ',' || *s == ';')
  704. ++s;
  705. }
  706. if (!*s)
  707. return n;
  708. }
  709. return 0; /* zero = nothing matched */
  710. }
  711. /*
  712. * ide_setup() gets called VERY EARLY during initialization,
  713. * to handle kernel "command line" strings beginning with "hdx=" or "ide".
  714. *
  715. * Remember to update Documentation/ide/ide.txt if you change something here.
  716. */
  717. static int __init ide_setup(char *s)
  718. {
  719. ide_hwif_t *hwif;
  720. ide_drive_t *drive;
  721. unsigned int hw, unit;
  722. int vals[3];
  723. const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
  724. if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
  725. return 0; /* driver and not us */
  726. if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
  727. return 0;
  728. printk(KERN_INFO "ide_setup: %s", s);
  729. init_ide_data ();
  730. #ifdef CONFIG_BLK_DEV_IDEDOUBLER
  731. if (!strcmp(s, "ide=doubler")) {
  732. extern int ide_doubler;
  733. printk(" : Enabled support for IDE doublers\n");
  734. ide_doubler = 1;
  735. return 1;
  736. }
  737. #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
  738. if (!strcmp(s, "ide=nodma")) {
  739. printk(" : Prevented DMA\n");
  740. noautodma = 1;
  741. goto obsolete_option;
  742. }
  743. #ifdef CONFIG_BLK_DEV_IDEACPI
  744. if (!strcmp(s, "ide=noacpi")) {
  745. //printk(" : Disable IDE ACPI support.\n");
  746. ide_noacpi = 1;
  747. return 1;
  748. }
  749. if (!strcmp(s, "ide=acpigtf")) {
  750. //printk(" : Enable IDE ACPI _GTF support.\n");
  751. ide_noacpitfs = 0;
  752. return 1;
  753. }
  754. if (!strcmp(s, "ide=acpionboot")) {
  755. //printk(" : Call IDE ACPI methods on boot.\n");
  756. ide_noacpionboot = 0;
  757. return 1;
  758. }
  759. #endif /* CONFIG_BLK_DEV_IDEACPI */
  760. /*
  761. * Look for drive options: "hdx="
  762. */
  763. if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
  764. const char *hd_words[] = {
  765. "none", "noprobe", "nowerr", "cdrom", "nodma",
  766. "-6", "-7", "-8", "-9", "-10",
  767. "noflush", "remap", "remap63", "scsi", NULL };
  768. unit = s[2] - 'a';
  769. hw = unit / MAX_DRIVES;
  770. unit = unit % MAX_DRIVES;
  771. hwif = &ide_hwifs[hw];
  772. drive = &hwif->drives[unit];
  773. if (strncmp(s + 4, "ide-", 4) == 0) {
  774. strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
  775. goto obsolete_option;
  776. }
  777. switch (match_parm(&s[3], hd_words, vals, 3)) {
  778. case -1: /* "none" */
  779. case -2: /* "noprobe" */
  780. drive->noprobe = 1;
  781. goto obsolete_option;
  782. case -3: /* "nowerr" */
  783. drive->bad_wstat = BAD_R_STAT;
  784. goto obsolete_option;
  785. case -4: /* "cdrom" */
  786. drive->present = 1;
  787. drive->media = ide_cdrom;
  788. /* an ATAPI device ignores DRDY */
  789. drive->ready_stat = 0;
  790. goto done;
  791. case -5: /* nodma */
  792. drive->nodma = 1;
  793. goto obsolete_option;
  794. case -11: /* noflush */
  795. drive->noflush = 1;
  796. goto obsolete_option;
  797. case -12: /* "remap" */
  798. drive->remap_0_to_1 = 1;
  799. goto obsolete_option;
  800. case -13: /* "remap63" */
  801. drive->sect0 = 63;
  802. goto obsolete_option;
  803. case -14: /* "scsi" */
  804. drive->scsi = 1;
  805. goto obsolete_option;
  806. case 3: /* cyl,head,sect */
  807. drive->media = ide_disk;
  808. drive->ready_stat = READY_STAT;
  809. drive->cyl = drive->bios_cyl = vals[0];
  810. drive->head = drive->bios_head = vals[1];
  811. drive->sect = drive->bios_sect = vals[2];
  812. drive->present = 1;
  813. drive->forced_geom = 1;
  814. goto done;
  815. default:
  816. goto bad_option;
  817. }
  818. }
  819. if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
  820. goto bad_option;
  821. /*
  822. * Look for bus speed option: "idebus="
  823. */
  824. if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
  825. if (match_parm(&s[6], NULL, vals, 1) != 1)
  826. goto bad_option;
  827. if (vals[0] >= 20 && vals[0] <= 66) {
  828. idebus_parameter = vals[0];
  829. } else
  830. printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
  831. goto obsolete_option;
  832. }
  833. bad_option:
  834. printk(" -- BAD OPTION\n");
  835. return 1;
  836. obsolete_option:
  837. printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
  838. return 1;
  839. done:
  840. printk("\n");
  841. return 1;
  842. }
  843. EXPORT_SYMBOL(ide_lock);
  844. static int ide_bus_match(struct device *dev, struct device_driver *drv)
  845. {
  846. return 1;
  847. }
  848. static char *media_string(ide_drive_t *drive)
  849. {
  850. switch (drive->media) {
  851. case ide_disk:
  852. return "disk";
  853. case ide_cdrom:
  854. return "cdrom";
  855. case ide_tape:
  856. return "tape";
  857. case ide_floppy:
  858. return "floppy";
  859. case ide_optical:
  860. return "optical";
  861. default:
  862. return "UNKNOWN";
  863. }
  864. }
  865. static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
  866. {
  867. ide_drive_t *drive = to_ide_device(dev);
  868. return sprintf(buf, "%s\n", media_string(drive));
  869. }
  870. static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
  871. {
  872. ide_drive_t *drive = to_ide_device(dev);
  873. return sprintf(buf, "%s\n", drive->name);
  874. }
  875. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
  876. {
  877. ide_drive_t *drive = to_ide_device(dev);
  878. return sprintf(buf, "ide:m-%s\n", media_string(drive));
  879. }
  880. static ssize_t model_show(struct device *dev, struct device_attribute *attr,
  881. char *buf)
  882. {
  883. ide_drive_t *drive = to_ide_device(dev);
  884. return sprintf(buf, "%s\n", drive->id->model);
  885. }
  886. static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
  887. char *buf)
  888. {
  889. ide_drive_t *drive = to_ide_device(dev);
  890. return sprintf(buf, "%s\n", drive->id->fw_rev);
  891. }
  892. static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
  893. char *buf)
  894. {
  895. ide_drive_t *drive = to_ide_device(dev);
  896. return sprintf(buf, "%s\n", drive->id->serial_no);
  897. }
  898. static struct device_attribute ide_dev_attrs[] = {
  899. __ATTR_RO(media),
  900. __ATTR_RO(drivename),
  901. __ATTR_RO(modalias),
  902. __ATTR_RO(model),
  903. __ATTR_RO(firmware),
  904. __ATTR(serial, 0400, serial_show, NULL),
  905. __ATTR_NULL
  906. };
  907. static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
  908. {
  909. ide_drive_t *drive = to_ide_device(dev);
  910. add_uevent_var(env, "MEDIA=%s", media_string(drive));
  911. add_uevent_var(env, "DRIVENAME=%s", drive->name);
  912. add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive));
  913. return 0;
  914. }
  915. static int generic_ide_probe(struct device *dev)
  916. {
  917. ide_drive_t *drive = to_ide_device(dev);
  918. ide_driver_t *drv = to_ide_driver(dev->driver);
  919. return drv->probe ? drv->probe(drive) : -ENODEV;
  920. }
  921. static int generic_ide_remove(struct device *dev)
  922. {
  923. ide_drive_t *drive = to_ide_device(dev);
  924. ide_driver_t *drv = to_ide_driver(dev->driver);
  925. if (drv->remove)
  926. drv->remove(drive);
  927. return 0;
  928. }
  929. static void generic_ide_shutdown(struct device *dev)
  930. {
  931. ide_drive_t *drive = to_ide_device(dev);
  932. ide_driver_t *drv = to_ide_driver(dev->driver);
  933. if (dev->driver && drv->shutdown)
  934. drv->shutdown(drive);
  935. }
  936. struct bus_type ide_bus_type = {
  937. .name = "ide",
  938. .match = ide_bus_match,
  939. .uevent = ide_uevent,
  940. .probe = generic_ide_probe,
  941. .remove = generic_ide_remove,
  942. .shutdown = generic_ide_shutdown,
  943. .dev_attrs = ide_dev_attrs,
  944. .suspend = generic_ide_suspend,
  945. .resume = generic_ide_resume,
  946. };
  947. EXPORT_SYMBOL_GPL(ide_bus_type);
  948. static void ide_port_class_release(struct device *portdev)
  949. {
  950. ide_hwif_t *hwif = dev_get_drvdata(portdev);
  951. put_device(&hwif->gendev);
  952. }
  953. int ide_vlb_clk;
  954. EXPORT_SYMBOL_GPL(ide_vlb_clk);
  955. module_param_named(vlb_clock, ide_vlb_clk, int, 0);
  956. MODULE_PARM_DESC(vlb_clock, "VLB clock frequency (in MHz)");
  957. int ide_pci_clk;
  958. EXPORT_SYMBOL_GPL(ide_pci_clk);
  959. module_param_named(pci_clock, ide_pci_clk, int, 0);
  960. MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)");
  961. static int ide_set_dev_param_mask(const char *s, struct kernel_param *kp)
  962. {
  963. int a, b, i, j = 1;
  964. unsigned int *dev_param_mask = (unsigned int *)kp->arg;
  965. if (sscanf(s, "%d.%d:%d", &a, &b, &j) != 3 &&
  966. sscanf(s, "%d.%d", &a, &b) != 2)
  967. return -EINVAL;
  968. i = a * MAX_DRIVES + b;
  969. if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
  970. return -EINVAL;
  971. if (j)
  972. *dev_param_mask |= (1 << i);
  973. else
  974. *dev_param_mask &= (1 << i);
  975. return 0;
  976. }
  977. static unsigned int ide_nodma;
  978. module_param_call(nodma, ide_set_dev_param_mask, NULL, &ide_nodma, 0);
  979. MODULE_PARM_DESC(nodma, "disallow DMA for a device");
  980. static unsigned int ide_noflush;
  981. module_param_call(noflush, ide_set_dev_param_mask, NULL, &ide_noflush, 0);
  982. MODULE_PARM_DESC(noflush, "disable flush requests for a device");
  983. static unsigned int ide_noprobe;
  984. module_param_call(noprobe, ide_set_dev_param_mask, NULL, &ide_noprobe, 0);
  985. MODULE_PARM_DESC(noprobe, "skip probing for a device");
  986. static unsigned int ide_nowerr;
  987. module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0);
  988. MODULE_PARM_DESC(nowerr, "ignore the WRERR_STAT bit for a device");
  989. static void ide_dev_apply_params(ide_drive_t *drive)
  990. {
  991. int i = drive->hwif->index * MAX_DRIVES + drive->select.b.unit;
  992. if (ide_nodma & (1 << i)) {
  993. printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
  994. drive->nodma = 1;
  995. }
  996. if (ide_noflush & (1 << i)) {
  997. printk(KERN_INFO "ide: disabling flush requests for %s\n",
  998. drive->name);
  999. drive->noflush = 1;
  1000. }
  1001. if (ide_noprobe & (1 << i)) {
  1002. printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
  1003. drive->noprobe = 1;
  1004. }
  1005. if (ide_nowerr & (1 << i)) {
  1006. printk(KERN_INFO "ide: ignoring the WRERR_STAT bit for %s\n",
  1007. drive->name);
  1008. drive->bad_wstat = BAD_R_STAT;
  1009. }
  1010. }
  1011. static unsigned int ide_ignore_cable;
  1012. static int ide_set_ignore_cable(const char *s, struct kernel_param *kp)
  1013. {
  1014. int i, j = 1;
  1015. if (sscanf(s, "%d:%d", &i, &j) != 2 && sscanf(s, "%d", &i) != 1)
  1016. return -EINVAL;
  1017. if (i >= MAX_HWIFS || j < 0 || j > 1)
  1018. return -EINVAL;
  1019. if (j)
  1020. ide_ignore_cable |= (1 << i);
  1021. else
  1022. ide_ignore_cable &= (1 << i);
  1023. return 0;
  1024. }
  1025. module_param_call(ignore_cable, ide_set_ignore_cable, NULL, NULL, 0);
  1026. MODULE_PARM_DESC(ignore_cable, "ignore cable detection");
  1027. void ide_port_apply_params(ide_hwif_t *hwif)
  1028. {
  1029. int i;
  1030. if (ide_ignore_cable & (1 << hwif->index)) {
  1031. printk(KERN_INFO "ide: ignoring cable detection for %s\n",
  1032. hwif->name);
  1033. hwif->cbl = ATA_CBL_PATA40_SHORT;
  1034. }
  1035. for (i = 0; i < MAX_DRIVES; i++)
  1036. ide_dev_apply_params(&hwif->drives[i]);
  1037. }
  1038. /*
  1039. * This is gets invoked once during initialization, to set *everything* up
  1040. */
  1041. static int __init ide_init(void)
  1042. {
  1043. int ret;
  1044. printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
  1045. system_bus_speed = ide_system_bus_speed();
  1046. printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
  1047. "for PIO modes%s\n", system_bus_speed,
  1048. idebus_parameter ? "" : "; override with idebus=xx");
  1049. ret = bus_register(&ide_bus_type);
  1050. if (ret < 0) {
  1051. printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
  1052. return ret;
  1053. }
  1054. ide_port_class = class_create(THIS_MODULE, "ide_port");
  1055. if (IS_ERR(ide_port_class)) {
  1056. ret = PTR_ERR(ide_port_class);
  1057. goto out_port_class;
  1058. }
  1059. ide_port_class->dev_release = ide_port_class_release;
  1060. init_ide_data();
  1061. proc_ide_create();
  1062. return 0;
  1063. out_port_class:
  1064. bus_unregister(&ide_bus_type);
  1065. return ret;
  1066. }
  1067. #ifdef MODULE
  1068. static char *options = NULL;
  1069. module_param(options, charp, 0);
  1070. MODULE_LICENSE("GPL");
  1071. static void __init parse_options (char *line)
  1072. {
  1073. char *next = line;
  1074. if (line == NULL || !*line)
  1075. return;
  1076. while ((line = next) != NULL) {
  1077. if ((next = strchr(line,' ')) != NULL)
  1078. *next++ = 0;
  1079. if (!ide_setup(line))
  1080. printk (KERN_INFO "Unknown option '%s'\n", line);
  1081. }
  1082. }
  1083. int __init init_module (void)
  1084. {
  1085. parse_options(options);
  1086. return ide_init();
  1087. }
  1088. void __exit cleanup_module (void)
  1089. {
  1090. int index;
  1091. for (index = 0; index < MAX_HWIFS; ++index)
  1092. ide_unregister(index);
  1093. proc_ide_destroy();
  1094. class_destroy(ide_port_class);
  1095. bus_unregister(&ide_bus_type);
  1096. }
  1097. #else /* !MODULE */
  1098. __setup("", ide_setup);
  1099. module_init(ide_init);
  1100. #endif /* MODULE */