ide.c 31 KB

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