ide.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /*
  2. * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
  3. * Copyright (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. #include <linux/module.h>
  46. #include <linux/types.h>
  47. #include <linux/string.h>
  48. #include <linux/kernel.h>
  49. #include <linux/interrupt.h>
  50. #include <linux/major.h>
  51. #include <linux/errno.h>
  52. #include <linux/genhd.h>
  53. #include <linux/slab.h>
  54. #include <linux/init.h>
  55. #include <linux/pci.h>
  56. #include <linux/ide.h>
  57. #include <linux/hdreg.h>
  58. #include <linux/completion.h>
  59. #include <linux/device.h>
  60. /* default maximum number of failures */
  61. #define IDE_DEFAULT_MAX_FAILURES 1
  62. struct class *ide_port_class;
  63. static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
  64. IDE2_MAJOR, IDE3_MAJOR,
  65. IDE4_MAJOR, IDE5_MAJOR,
  66. IDE6_MAJOR, IDE7_MAJOR,
  67. IDE8_MAJOR, IDE9_MAJOR };
  68. DEFINE_MUTEX(ide_cfg_mtx);
  69. static void ide_port_init_devices_data(ide_hwif_t *);
  70. /*
  71. * Do not even *think* about calling this!
  72. */
  73. void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
  74. {
  75. /* bulk initialize hwif & drive info with zeros */
  76. memset(hwif, 0, sizeof(ide_hwif_t));
  77. /* fill in any non-zero initial values */
  78. hwif->index = index;
  79. hwif->major = ide_hwif_to_major[index];
  80. hwif->name[0] = 'i';
  81. hwif->name[1] = 'd';
  82. hwif->name[2] = 'e';
  83. hwif->name[3] = '0' + index;
  84. init_completion(&hwif->gendev_rel_comp);
  85. hwif->tp_ops = &default_tp_ops;
  86. ide_port_init_devices_data(hwif);
  87. }
  88. static void ide_port_init_devices_data(ide_hwif_t *hwif)
  89. {
  90. int unit;
  91. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  92. ide_drive_t *drive = &hwif->drives[unit];
  93. u8 j = (hwif->index * MAX_DRIVES) + unit;
  94. memset(drive, 0, sizeof(*drive));
  95. drive->media = ide_disk;
  96. drive->select = (unit << 4) | ATA_DEVICE_OBS;
  97. drive->hwif = hwif;
  98. drive->ready_stat = ATA_DRDY;
  99. drive->bad_wstat = BAD_W_STAT;
  100. drive->special.b.recalibrate = 1;
  101. drive->special.b.set_geometry = 1;
  102. drive->name[0] = 'h';
  103. drive->name[1] = 'd';
  104. drive->name[2] = 'a' + j;
  105. drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
  106. INIT_LIST_HEAD(&drive->list);
  107. init_completion(&drive->gendev_rel_comp);
  108. }
  109. }
  110. static void __ide_port_unregister_devices(ide_hwif_t *hwif)
  111. {
  112. int i;
  113. for (i = 0; i < MAX_DRIVES; i++) {
  114. ide_drive_t *drive = &hwif->drives[i];
  115. if (drive->dev_flags & IDE_DFLAG_PRESENT) {
  116. device_unregister(&drive->gendev);
  117. wait_for_completion(&drive->gendev_rel_comp);
  118. }
  119. }
  120. }
  121. void ide_port_unregister_devices(ide_hwif_t *hwif)
  122. {
  123. mutex_lock(&ide_cfg_mtx);
  124. __ide_port_unregister_devices(hwif);
  125. hwif->present = 0;
  126. ide_port_init_devices_data(hwif);
  127. mutex_unlock(&ide_cfg_mtx);
  128. }
  129. EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
  130. /**
  131. * ide_unregister - free an IDE interface
  132. * @hwif: IDE interface
  133. *
  134. * Perform the final unregister of an IDE interface. At the moment
  135. * we don't refcount interfaces so this will also get split up.
  136. *
  137. * Locking:
  138. * The caller must not hold the IDE locks
  139. * The drive present/vanishing is not yet properly locked
  140. * Take care with the callbacks. These have been split to avoid
  141. * deadlocking the IDE layer. The shutdown callback is called
  142. * before we take the lock and free resources. It is up to the
  143. * caller to be sure there is no pending I/O here, and that
  144. * the interface will not be reopened (present/vanishing locking
  145. * isn't yet done BTW). After we commit to the final kill we
  146. * call the cleanup callback with the ide locks held.
  147. *
  148. * Unregister restores the hwif structures to the default state.
  149. * This is raving bonkers.
  150. */
  151. void ide_unregister(ide_hwif_t *hwif)
  152. {
  153. BUG_ON(in_interrupt());
  154. BUG_ON(irqs_disabled());
  155. mutex_lock(&ide_cfg_mtx);
  156. if (hwif->present) {
  157. __ide_port_unregister_devices(hwif);
  158. hwif->present = 0;
  159. }
  160. ide_proc_unregister_port(hwif);
  161. free_irq(hwif->irq, hwif);
  162. device_unregister(hwif->portdev);
  163. device_unregister(&hwif->gendev);
  164. wait_for_completion(&hwif->gendev_rel_comp);
  165. /*
  166. * Remove us from the kernel's knowledge
  167. */
  168. blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
  169. kfree(hwif->sg_table);
  170. unregister_blkdev(hwif->major, hwif->name);
  171. ide_release_dma_engine(hwif);
  172. mutex_unlock(&ide_cfg_mtx);
  173. }
  174. void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
  175. {
  176. memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports));
  177. hwif->irq = hw->irq;
  178. hwif->chipset = hw->chipset;
  179. hwif->dev = hw->dev;
  180. hwif->gendev.parent = hw->parent ? hw->parent : hw->dev;
  181. hwif->ack_intr = hw->ack_intr;
  182. hwif->config_data = hw->config;
  183. }
  184. /*
  185. * Locks for IDE setting functionality
  186. */
  187. DEFINE_MUTEX(ide_setting_mtx);
  188. ide_devset_get(io_32bit, io_32bit);
  189. static int set_io_32bit(ide_drive_t *drive, int arg)
  190. {
  191. if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT)
  192. return -EPERM;
  193. if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
  194. return -EINVAL;
  195. drive->io_32bit = arg;
  196. return 0;
  197. }
  198. ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS);
  199. static int set_ksettings(ide_drive_t *drive, int arg)
  200. {
  201. if (arg < 0 || arg > 1)
  202. return -EINVAL;
  203. if (arg)
  204. drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS;
  205. else
  206. drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS;
  207. return 0;
  208. }
  209. ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA);
  210. static int set_using_dma(ide_drive_t *drive, int arg)
  211. {
  212. #ifdef CONFIG_BLK_DEV_IDEDMA
  213. int err = -EPERM;
  214. if (arg < 0 || arg > 1)
  215. return -EINVAL;
  216. if (ata_id_has_dma(drive->id) == 0)
  217. goto out;
  218. if (drive->hwif->dma_ops == NULL)
  219. goto out;
  220. err = 0;
  221. if (arg) {
  222. if (ide_set_dma(drive))
  223. err = -EIO;
  224. } else
  225. ide_dma_off(drive);
  226. out:
  227. return err;
  228. #else
  229. if (arg < 0 || arg > 1)
  230. return -EINVAL;
  231. return -EPERM;
  232. #endif
  233. }
  234. /*
  235. * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
  236. */
  237. static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
  238. {
  239. switch (req_pio) {
  240. case 202:
  241. case 201:
  242. case 200:
  243. case 102:
  244. case 101:
  245. case 100:
  246. return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
  247. case 9:
  248. case 8:
  249. return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
  250. case 7:
  251. case 6:
  252. return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
  253. default:
  254. return 0;
  255. }
  256. }
  257. static int set_pio_mode(ide_drive_t *drive, int arg)
  258. {
  259. ide_hwif_t *hwif = drive->hwif;
  260. const struct ide_port_ops *port_ops = hwif->port_ops;
  261. if (arg < 0 || arg > 255)
  262. return -EINVAL;
  263. if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
  264. (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
  265. return -ENOSYS;
  266. if (set_pio_mode_abuse(drive->hwif, arg)) {
  267. if (arg == 8 || arg == 9) {
  268. unsigned long flags;
  269. /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
  270. spin_lock_irqsave(&hwif->lock, flags);
  271. port_ops->set_pio_mode(drive, arg);
  272. spin_unlock_irqrestore(&hwif->lock, flags);
  273. } else
  274. port_ops->set_pio_mode(drive, arg);
  275. } else {
  276. int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
  277. ide_set_pio(drive, arg);
  278. if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
  279. if (keep_dma)
  280. ide_dma_on(drive);
  281. }
  282. }
  283. return 0;
  284. }
  285. ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK);
  286. static int set_unmaskirq(ide_drive_t *drive, int arg)
  287. {
  288. if (drive->dev_flags & IDE_DFLAG_NO_UNMASK)
  289. return -EPERM;
  290. if (arg < 0 || arg > 1)
  291. return -EINVAL;
  292. if (arg)
  293. drive->dev_flags |= IDE_DFLAG_UNMASK;
  294. else
  295. drive->dev_flags &= ~IDE_DFLAG_UNMASK;
  296. return 0;
  297. }
  298. ide_ext_devset_rw_sync(io_32bit, io_32bit);
  299. ide_ext_devset_rw_sync(keepsettings, ksettings);
  300. ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
  301. ide_ext_devset_rw_sync(using_dma, using_dma);
  302. __IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
  303. /**
  304. * ide_device_get - get an additional reference to a ide_drive_t
  305. * @drive: device to get a reference to
  306. *
  307. * Gets a reference to the ide_drive_t and increments the use count of the
  308. * underlying LLDD module.
  309. */
  310. int ide_device_get(ide_drive_t *drive)
  311. {
  312. struct device *host_dev;
  313. struct module *module;
  314. if (!get_device(&drive->gendev))
  315. return -ENXIO;
  316. host_dev = drive->hwif->host->dev[0];
  317. module = host_dev ? host_dev->driver->owner : NULL;
  318. if (module && !try_module_get(module)) {
  319. put_device(&drive->gendev);
  320. return -ENXIO;
  321. }
  322. return 0;
  323. }
  324. EXPORT_SYMBOL_GPL(ide_device_get);
  325. /**
  326. * ide_device_put - release a reference to a ide_drive_t
  327. * @drive: device to release a reference on
  328. *
  329. * Release a reference to the ide_drive_t and decrements the use count of
  330. * the underlying LLDD module.
  331. */
  332. void ide_device_put(ide_drive_t *drive)
  333. {
  334. #ifdef CONFIG_MODULE_UNLOAD
  335. struct device *host_dev = drive->hwif->host->dev[0];
  336. struct module *module = host_dev ? host_dev->driver->owner : NULL;
  337. if (module)
  338. module_put(module);
  339. #endif
  340. put_device(&drive->gendev);
  341. }
  342. EXPORT_SYMBOL_GPL(ide_device_put);
  343. static int ide_bus_match(struct device *dev, struct device_driver *drv)
  344. {
  345. return 1;
  346. }
  347. static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
  348. {
  349. ide_drive_t *drive = to_ide_device(dev);
  350. add_uevent_var(env, "MEDIA=%s", ide_media_string(drive));
  351. add_uevent_var(env, "DRIVENAME=%s", drive->name);
  352. add_uevent_var(env, "MODALIAS=ide:m-%s", ide_media_string(drive));
  353. return 0;
  354. }
  355. static int generic_ide_probe(struct device *dev)
  356. {
  357. ide_drive_t *drive = to_ide_device(dev);
  358. ide_driver_t *drv = to_ide_driver(dev->driver);
  359. return drv->probe ? drv->probe(drive) : -ENODEV;
  360. }
  361. static int generic_ide_remove(struct device *dev)
  362. {
  363. ide_drive_t *drive = to_ide_device(dev);
  364. ide_driver_t *drv = to_ide_driver(dev->driver);
  365. if (drv->remove)
  366. drv->remove(drive);
  367. return 0;
  368. }
  369. static void generic_ide_shutdown(struct device *dev)
  370. {
  371. ide_drive_t *drive = to_ide_device(dev);
  372. ide_driver_t *drv = to_ide_driver(dev->driver);
  373. if (dev->driver && drv->shutdown)
  374. drv->shutdown(drive);
  375. }
  376. struct bus_type ide_bus_type = {
  377. .name = "ide",
  378. .match = ide_bus_match,
  379. .uevent = ide_uevent,
  380. .probe = generic_ide_probe,
  381. .remove = generic_ide_remove,
  382. .shutdown = generic_ide_shutdown,
  383. .dev_attrs = ide_dev_attrs,
  384. .suspend = generic_ide_suspend,
  385. .resume = generic_ide_resume,
  386. };
  387. EXPORT_SYMBOL_GPL(ide_bus_type);
  388. int ide_vlb_clk;
  389. EXPORT_SYMBOL_GPL(ide_vlb_clk);
  390. module_param_named(vlb_clock, ide_vlb_clk, int, 0);
  391. MODULE_PARM_DESC(vlb_clock, "VLB clock frequency (in MHz)");
  392. int ide_pci_clk;
  393. EXPORT_SYMBOL_GPL(ide_pci_clk);
  394. module_param_named(pci_clock, ide_pci_clk, int, 0);
  395. MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)");
  396. static int ide_set_dev_param_mask(const char *s, struct kernel_param *kp)
  397. {
  398. int a, b, i, j = 1;
  399. unsigned int *dev_param_mask = (unsigned int *)kp->arg;
  400. if (sscanf(s, "%d.%d:%d", &a, &b, &j) != 3 &&
  401. sscanf(s, "%d.%d", &a, &b) != 2)
  402. return -EINVAL;
  403. i = a * MAX_DRIVES + b;
  404. if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
  405. return -EINVAL;
  406. if (j)
  407. *dev_param_mask |= (1 << i);
  408. else
  409. *dev_param_mask &= (1 << i);
  410. return 0;
  411. }
  412. static unsigned int ide_nodma;
  413. module_param_call(nodma, ide_set_dev_param_mask, NULL, &ide_nodma, 0);
  414. MODULE_PARM_DESC(nodma, "disallow DMA for a device");
  415. static unsigned int ide_noflush;
  416. module_param_call(noflush, ide_set_dev_param_mask, NULL, &ide_noflush, 0);
  417. MODULE_PARM_DESC(noflush, "disable flush requests for a device");
  418. static unsigned int ide_noprobe;
  419. module_param_call(noprobe, ide_set_dev_param_mask, NULL, &ide_noprobe, 0);
  420. MODULE_PARM_DESC(noprobe, "skip probing for a device");
  421. static unsigned int ide_nowerr;
  422. module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0);
  423. MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device");
  424. static unsigned int ide_cdroms;
  425. module_param_call(cdrom, ide_set_dev_param_mask, NULL, &ide_cdroms, 0);
  426. MODULE_PARM_DESC(cdrom, "force device as a CD-ROM");
  427. struct chs_geom {
  428. unsigned int cyl;
  429. u8 head;
  430. u8 sect;
  431. };
  432. static unsigned int ide_disks;
  433. static struct chs_geom ide_disks_chs[MAX_HWIFS * MAX_DRIVES];
  434. static int ide_set_disk_chs(const char *str, struct kernel_param *kp)
  435. {
  436. int a, b, c = 0, h = 0, s = 0, i, j = 1;
  437. if (sscanf(str, "%d.%d:%d,%d,%d", &a, &b, &c, &h, &s) != 5 &&
  438. sscanf(str, "%d.%d:%d", &a, &b, &j) != 3)
  439. return -EINVAL;
  440. i = a * MAX_DRIVES + b;
  441. if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
  442. return -EINVAL;
  443. if (c > INT_MAX || h > 255 || s > 255)
  444. return -EINVAL;
  445. if (j)
  446. ide_disks |= (1 << i);
  447. else
  448. ide_disks &= (1 << i);
  449. ide_disks_chs[i].cyl = c;
  450. ide_disks_chs[i].head = h;
  451. ide_disks_chs[i].sect = s;
  452. return 0;
  453. }
  454. module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0);
  455. MODULE_PARM_DESC(chs, "force device as a disk (using CHS)");
  456. static void ide_dev_apply_params(ide_drive_t *drive, u8 unit)
  457. {
  458. int i = drive->hwif->index * MAX_DRIVES + unit;
  459. if (ide_nodma & (1 << i)) {
  460. printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
  461. drive->dev_flags |= IDE_DFLAG_NODMA;
  462. }
  463. if (ide_noflush & (1 << i)) {
  464. printk(KERN_INFO "ide: disabling flush requests for %s\n",
  465. drive->name);
  466. drive->dev_flags |= IDE_DFLAG_NOFLUSH;
  467. }
  468. if (ide_noprobe & (1 << i)) {
  469. printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
  470. drive->dev_flags |= IDE_DFLAG_NOPROBE;
  471. }
  472. if (ide_nowerr & (1 << i)) {
  473. printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
  474. drive->name);
  475. drive->bad_wstat = BAD_R_STAT;
  476. }
  477. if (ide_cdroms & (1 << i)) {
  478. printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name);
  479. drive->dev_flags |= IDE_DFLAG_PRESENT;
  480. drive->media = ide_cdrom;
  481. /* an ATAPI device ignores DRDY */
  482. drive->ready_stat = 0;
  483. }
  484. if (ide_disks & (1 << i)) {
  485. drive->cyl = drive->bios_cyl = ide_disks_chs[i].cyl;
  486. drive->head = drive->bios_head = ide_disks_chs[i].head;
  487. drive->sect = drive->bios_sect = ide_disks_chs[i].sect;
  488. printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n",
  489. drive->name,
  490. drive->cyl, drive->head, drive->sect);
  491. drive->dev_flags |= IDE_DFLAG_FORCED_GEOM | IDE_DFLAG_PRESENT;
  492. drive->media = ide_disk;
  493. drive->ready_stat = ATA_DRDY;
  494. }
  495. }
  496. static unsigned int ide_ignore_cable;
  497. static int ide_set_ignore_cable(const char *s, struct kernel_param *kp)
  498. {
  499. int i, j = 1;
  500. if (sscanf(s, "%d:%d", &i, &j) != 2 && sscanf(s, "%d", &i) != 1)
  501. return -EINVAL;
  502. if (i >= MAX_HWIFS || j < 0 || j > 1)
  503. return -EINVAL;
  504. if (j)
  505. ide_ignore_cable |= (1 << i);
  506. else
  507. ide_ignore_cable &= (1 << i);
  508. return 0;
  509. }
  510. module_param_call(ignore_cable, ide_set_ignore_cable, NULL, NULL, 0);
  511. MODULE_PARM_DESC(ignore_cable, "ignore cable detection");
  512. void ide_port_apply_params(ide_hwif_t *hwif)
  513. {
  514. int i;
  515. if (ide_ignore_cable & (1 << hwif->index)) {
  516. printk(KERN_INFO "ide: ignoring cable detection for %s\n",
  517. hwif->name);
  518. hwif->cbl = ATA_CBL_PATA40_SHORT;
  519. }
  520. for (i = 0; i < MAX_DRIVES; i++)
  521. ide_dev_apply_params(&hwif->drives[i], i);
  522. }
  523. /*
  524. * This is gets invoked once during initialization, to set *everything* up
  525. */
  526. static int __init ide_init(void)
  527. {
  528. int ret;
  529. printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
  530. ret = bus_register(&ide_bus_type);
  531. if (ret < 0) {
  532. printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
  533. return ret;
  534. }
  535. ide_port_class = class_create(THIS_MODULE, "ide_port");
  536. if (IS_ERR(ide_port_class)) {
  537. ret = PTR_ERR(ide_port_class);
  538. goto out_port_class;
  539. }
  540. proc_ide_create();
  541. return 0;
  542. out_port_class:
  543. bus_unregister(&ide_bus_type);
  544. return ret;
  545. }
  546. static void __exit ide_exit(void)
  547. {
  548. proc_ide_destroy();
  549. class_destroy(ide_port_class);
  550. bus_unregister(&ide_bus_type);
  551. }
  552. module_init(ide_init);
  553. module_exit(ide_exit);
  554. MODULE_LICENSE("GPL");