ide.c 33 KB

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