ide.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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. ide_hwif_t *g;
  154. ide_hwgroup_t *hwgroup;
  155. int irq_count = 0;
  156. BUG_ON(in_interrupt());
  157. BUG_ON(irqs_disabled());
  158. mutex_lock(&ide_cfg_mtx);
  159. if (hwif->present) {
  160. __ide_port_unregister_devices(hwif);
  161. hwif->present = 0;
  162. }
  163. ide_proc_unregister_port(hwif);
  164. hwgroup = hwif->hwgroup;
  165. /*
  166. * free the irq if we were the only hwif using it
  167. */
  168. g = hwgroup->hwif;
  169. do {
  170. if (g->irq == hwif->irq)
  171. ++irq_count;
  172. g = g->next;
  173. } while (g != hwgroup->hwif);
  174. if (irq_count == 1)
  175. free_irq(hwif->irq, hwgroup);
  176. ide_remove_port_from_hwgroup(hwif);
  177. device_unregister(hwif->portdev);
  178. device_unregister(&hwif->gendev);
  179. wait_for_completion(&hwif->gendev_rel_comp);
  180. /*
  181. * Remove us from the kernel's knowledge
  182. */
  183. blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
  184. kfree(hwif->sg_table);
  185. unregister_blkdev(hwif->major, hwif->name);
  186. ide_release_dma_engine(hwif);
  187. mutex_unlock(&ide_cfg_mtx);
  188. }
  189. void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
  190. {
  191. memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports));
  192. hwif->irq = hw->irq;
  193. hwif->chipset = hw->chipset;
  194. hwif->dev = hw->dev;
  195. hwif->gendev.parent = hw->parent ? hw->parent : hw->dev;
  196. hwif->ack_intr = hw->ack_intr;
  197. hwif->config_data = hw->config;
  198. }
  199. /*
  200. * Locks for IDE setting functionality
  201. */
  202. DEFINE_MUTEX(ide_setting_mtx);
  203. ide_devset_get(io_32bit, io_32bit);
  204. static int set_io_32bit(ide_drive_t *drive, int arg)
  205. {
  206. if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT)
  207. return -EPERM;
  208. if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
  209. return -EINVAL;
  210. drive->io_32bit = arg;
  211. return 0;
  212. }
  213. ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS);
  214. static int set_ksettings(ide_drive_t *drive, int arg)
  215. {
  216. if (arg < 0 || arg > 1)
  217. return -EINVAL;
  218. if (arg)
  219. drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS;
  220. else
  221. drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS;
  222. return 0;
  223. }
  224. ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA);
  225. static int set_using_dma(ide_drive_t *drive, int arg)
  226. {
  227. #ifdef CONFIG_BLK_DEV_IDEDMA
  228. int err = -EPERM;
  229. if (arg < 0 || arg > 1)
  230. return -EINVAL;
  231. if (ata_id_has_dma(drive->id) == 0)
  232. goto out;
  233. if (drive->hwif->dma_ops == NULL)
  234. goto out;
  235. err = 0;
  236. if (arg) {
  237. if (ide_set_dma(drive))
  238. err = -EIO;
  239. } else
  240. ide_dma_off(drive);
  241. out:
  242. return err;
  243. #else
  244. if (arg < 0 || arg > 1)
  245. return -EINVAL;
  246. return -EPERM;
  247. #endif
  248. }
  249. /*
  250. * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
  251. */
  252. static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
  253. {
  254. switch (req_pio) {
  255. case 202:
  256. case 201:
  257. case 200:
  258. case 102:
  259. case 101:
  260. case 100:
  261. return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
  262. case 9:
  263. case 8:
  264. return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
  265. case 7:
  266. case 6:
  267. return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
  268. default:
  269. return 0;
  270. }
  271. }
  272. static int set_pio_mode(ide_drive_t *drive, int arg)
  273. {
  274. ide_hwif_t *hwif = drive->hwif;
  275. ide_hwgroup_t *hwgroup = hwif->hwgroup;
  276. const struct ide_port_ops *port_ops = hwif->port_ops;
  277. if (arg < 0 || arg > 255)
  278. return -EINVAL;
  279. if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
  280. (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
  281. return -ENOSYS;
  282. if (set_pio_mode_abuse(drive->hwif, arg)) {
  283. if (arg == 8 || arg == 9) {
  284. unsigned long flags;
  285. /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
  286. spin_lock_irqsave(&hwgroup->lock, flags);
  287. port_ops->set_pio_mode(drive, arg);
  288. spin_unlock_irqrestore(&hwgroup->lock, flags);
  289. } else
  290. port_ops->set_pio_mode(drive, arg);
  291. } else {
  292. int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
  293. ide_set_pio(drive, arg);
  294. if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
  295. if (keep_dma)
  296. ide_dma_on(drive);
  297. }
  298. }
  299. return 0;
  300. }
  301. ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK);
  302. static int set_unmaskirq(ide_drive_t *drive, int arg)
  303. {
  304. if (drive->dev_flags & IDE_DFLAG_NO_UNMASK)
  305. return -EPERM;
  306. if (arg < 0 || arg > 1)
  307. return -EINVAL;
  308. if (arg)
  309. drive->dev_flags |= IDE_DFLAG_UNMASK;
  310. else
  311. drive->dev_flags &= ~IDE_DFLAG_UNMASK;
  312. return 0;
  313. }
  314. ide_ext_devset_rw_sync(io_32bit, io_32bit);
  315. ide_ext_devset_rw_sync(keepsettings, ksettings);
  316. ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
  317. ide_ext_devset_rw_sync(using_dma, using_dma);
  318. __IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
  319. /**
  320. * ide_device_get - get an additional reference to a ide_drive_t
  321. * @drive: device to get a reference to
  322. *
  323. * Gets a reference to the ide_drive_t and increments the use count of the
  324. * underlying LLDD module.
  325. */
  326. int ide_device_get(ide_drive_t *drive)
  327. {
  328. struct device *host_dev;
  329. struct module *module;
  330. if (!get_device(&drive->gendev))
  331. return -ENXIO;
  332. host_dev = drive->hwif->host->dev[0];
  333. module = host_dev ? host_dev->driver->owner : NULL;
  334. if (module && !try_module_get(module)) {
  335. put_device(&drive->gendev);
  336. return -ENXIO;
  337. }
  338. return 0;
  339. }
  340. EXPORT_SYMBOL_GPL(ide_device_get);
  341. /**
  342. * ide_device_put - release a reference to a ide_drive_t
  343. * @drive: device to release a reference on
  344. *
  345. * Release a reference to the ide_drive_t and decrements the use count of
  346. * the underlying LLDD module.
  347. */
  348. void ide_device_put(ide_drive_t *drive)
  349. {
  350. #ifdef CONFIG_MODULE_UNLOAD
  351. struct device *host_dev = drive->hwif->host->dev[0];
  352. struct module *module = host_dev ? host_dev->driver->owner : NULL;
  353. if (module)
  354. module_put(module);
  355. #endif
  356. put_device(&drive->gendev);
  357. }
  358. EXPORT_SYMBOL_GPL(ide_device_put);
  359. static int ide_bus_match(struct device *dev, struct device_driver *drv)
  360. {
  361. return 1;
  362. }
  363. static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
  364. {
  365. ide_drive_t *drive = to_ide_device(dev);
  366. add_uevent_var(env, "MEDIA=%s", ide_media_string(drive));
  367. add_uevent_var(env, "DRIVENAME=%s", drive->name);
  368. add_uevent_var(env, "MODALIAS=ide:m-%s", ide_media_string(drive));
  369. return 0;
  370. }
  371. static int generic_ide_probe(struct device *dev)
  372. {
  373. ide_drive_t *drive = to_ide_device(dev);
  374. ide_driver_t *drv = to_ide_driver(dev->driver);
  375. return drv->probe ? drv->probe(drive) : -ENODEV;
  376. }
  377. static int generic_ide_remove(struct device *dev)
  378. {
  379. ide_drive_t *drive = to_ide_device(dev);
  380. ide_driver_t *drv = to_ide_driver(dev->driver);
  381. if (drv->remove)
  382. drv->remove(drive);
  383. return 0;
  384. }
  385. static void generic_ide_shutdown(struct device *dev)
  386. {
  387. ide_drive_t *drive = to_ide_device(dev);
  388. ide_driver_t *drv = to_ide_driver(dev->driver);
  389. if (dev->driver && drv->shutdown)
  390. drv->shutdown(drive);
  391. }
  392. struct bus_type ide_bus_type = {
  393. .name = "ide",
  394. .match = ide_bus_match,
  395. .uevent = ide_uevent,
  396. .probe = generic_ide_probe,
  397. .remove = generic_ide_remove,
  398. .shutdown = generic_ide_shutdown,
  399. .dev_attrs = ide_dev_attrs,
  400. .suspend = generic_ide_suspend,
  401. .resume = generic_ide_resume,
  402. };
  403. EXPORT_SYMBOL_GPL(ide_bus_type);
  404. int ide_vlb_clk;
  405. EXPORT_SYMBOL_GPL(ide_vlb_clk);
  406. module_param_named(vlb_clock, ide_vlb_clk, int, 0);
  407. MODULE_PARM_DESC(vlb_clock, "VLB clock frequency (in MHz)");
  408. int ide_pci_clk;
  409. EXPORT_SYMBOL_GPL(ide_pci_clk);
  410. module_param_named(pci_clock, ide_pci_clk, int, 0);
  411. MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)");
  412. static int ide_set_dev_param_mask(const char *s, struct kernel_param *kp)
  413. {
  414. int a, b, i, j = 1;
  415. unsigned int *dev_param_mask = (unsigned int *)kp->arg;
  416. if (sscanf(s, "%d.%d:%d", &a, &b, &j) != 3 &&
  417. sscanf(s, "%d.%d", &a, &b) != 2)
  418. return -EINVAL;
  419. i = a * MAX_DRIVES + b;
  420. if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
  421. return -EINVAL;
  422. if (j)
  423. *dev_param_mask |= (1 << i);
  424. else
  425. *dev_param_mask &= (1 << i);
  426. return 0;
  427. }
  428. static unsigned int ide_nodma;
  429. module_param_call(nodma, ide_set_dev_param_mask, NULL, &ide_nodma, 0);
  430. MODULE_PARM_DESC(nodma, "disallow DMA for a device");
  431. static unsigned int ide_noflush;
  432. module_param_call(noflush, ide_set_dev_param_mask, NULL, &ide_noflush, 0);
  433. MODULE_PARM_DESC(noflush, "disable flush requests for a device");
  434. static unsigned int ide_noprobe;
  435. module_param_call(noprobe, ide_set_dev_param_mask, NULL, &ide_noprobe, 0);
  436. MODULE_PARM_DESC(noprobe, "skip probing for a device");
  437. static unsigned int ide_nowerr;
  438. module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0);
  439. MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device");
  440. static unsigned int ide_cdroms;
  441. module_param_call(cdrom, ide_set_dev_param_mask, NULL, &ide_cdroms, 0);
  442. MODULE_PARM_DESC(cdrom, "force device as a CD-ROM");
  443. struct chs_geom {
  444. unsigned int cyl;
  445. u8 head;
  446. u8 sect;
  447. };
  448. static unsigned int ide_disks;
  449. static struct chs_geom ide_disks_chs[MAX_HWIFS * MAX_DRIVES];
  450. static int ide_set_disk_chs(const char *str, struct kernel_param *kp)
  451. {
  452. int a, b, c = 0, h = 0, s = 0, i, j = 1;
  453. if (sscanf(str, "%d.%d:%d,%d,%d", &a, &b, &c, &h, &s) != 5 &&
  454. sscanf(str, "%d.%d:%d", &a, &b, &j) != 3)
  455. return -EINVAL;
  456. i = a * MAX_DRIVES + b;
  457. if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
  458. return -EINVAL;
  459. if (c > INT_MAX || h > 255 || s > 255)
  460. return -EINVAL;
  461. if (j)
  462. ide_disks |= (1 << i);
  463. else
  464. ide_disks &= (1 << i);
  465. ide_disks_chs[i].cyl = c;
  466. ide_disks_chs[i].head = h;
  467. ide_disks_chs[i].sect = s;
  468. return 0;
  469. }
  470. module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0);
  471. MODULE_PARM_DESC(chs, "force device as a disk (using CHS)");
  472. static void ide_dev_apply_params(ide_drive_t *drive, u8 unit)
  473. {
  474. int i = drive->hwif->index * MAX_DRIVES + unit;
  475. if (ide_nodma & (1 << i)) {
  476. printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
  477. drive->dev_flags |= IDE_DFLAG_NODMA;
  478. }
  479. if (ide_noflush & (1 << i)) {
  480. printk(KERN_INFO "ide: disabling flush requests for %s\n",
  481. drive->name);
  482. drive->dev_flags |= IDE_DFLAG_NOFLUSH;
  483. }
  484. if (ide_noprobe & (1 << i)) {
  485. printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
  486. drive->dev_flags |= IDE_DFLAG_NOPROBE;
  487. }
  488. if (ide_nowerr & (1 << i)) {
  489. printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
  490. drive->name);
  491. drive->bad_wstat = BAD_R_STAT;
  492. }
  493. if (ide_cdroms & (1 << i)) {
  494. printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name);
  495. drive->dev_flags |= IDE_DFLAG_PRESENT;
  496. drive->media = ide_cdrom;
  497. /* an ATAPI device ignores DRDY */
  498. drive->ready_stat = 0;
  499. }
  500. if (ide_disks & (1 << i)) {
  501. drive->cyl = drive->bios_cyl = ide_disks_chs[i].cyl;
  502. drive->head = drive->bios_head = ide_disks_chs[i].head;
  503. drive->sect = drive->bios_sect = ide_disks_chs[i].sect;
  504. printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n",
  505. drive->name,
  506. drive->cyl, drive->head, drive->sect);
  507. drive->dev_flags |= IDE_DFLAG_FORCED_GEOM | IDE_DFLAG_PRESENT;
  508. drive->media = ide_disk;
  509. drive->ready_stat = ATA_DRDY;
  510. }
  511. }
  512. static unsigned int ide_ignore_cable;
  513. static int ide_set_ignore_cable(const char *s, struct kernel_param *kp)
  514. {
  515. int i, j = 1;
  516. if (sscanf(s, "%d:%d", &i, &j) != 2 && sscanf(s, "%d", &i) != 1)
  517. return -EINVAL;
  518. if (i >= MAX_HWIFS || j < 0 || j > 1)
  519. return -EINVAL;
  520. if (j)
  521. ide_ignore_cable |= (1 << i);
  522. else
  523. ide_ignore_cable &= (1 << i);
  524. return 0;
  525. }
  526. module_param_call(ignore_cable, ide_set_ignore_cable, NULL, NULL, 0);
  527. MODULE_PARM_DESC(ignore_cable, "ignore cable detection");
  528. void ide_port_apply_params(ide_hwif_t *hwif)
  529. {
  530. int i;
  531. if (ide_ignore_cable & (1 << hwif->index)) {
  532. printk(KERN_INFO "ide: ignoring cable detection for %s\n",
  533. hwif->name);
  534. hwif->cbl = ATA_CBL_PATA40_SHORT;
  535. }
  536. for (i = 0; i < MAX_DRIVES; i++)
  537. ide_dev_apply_params(&hwif->drives[i], i);
  538. }
  539. /*
  540. * This is gets invoked once during initialization, to set *everything* up
  541. */
  542. static int __init ide_init(void)
  543. {
  544. int ret;
  545. printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
  546. ret = bus_register(&ide_bus_type);
  547. if (ret < 0) {
  548. printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
  549. return ret;
  550. }
  551. ide_port_class = class_create(THIS_MODULE, "ide_port");
  552. if (IS_ERR(ide_port_class)) {
  553. ret = PTR_ERR(ide_port_class);
  554. goto out_port_class;
  555. }
  556. proc_ide_create();
  557. return 0;
  558. out_port_class:
  559. bus_unregister(&ide_bus_type);
  560. return ret;
  561. }
  562. static void __exit ide_exit(void)
  563. {
  564. proc_ide_destroy();
  565. class_destroy(ide_port_class);
  566. bus_unregister(&ide_bus_type);
  567. }
  568. module_init(ide_init);
  569. module_exit(ide_exit);
  570. MODULE_LICENSE("GPL");