ide.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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. __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
  70. EXPORT_SYMBOL(ide_lock);
  71. static void ide_port_init_devices_data(ide_hwif_t *);
  72. /*
  73. * Do not even *think* about calling this!
  74. */
  75. void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
  76. {
  77. /* bulk initialize hwif & drive info with zeros */
  78. memset(hwif, 0, sizeof(ide_hwif_t));
  79. /* fill in any non-zero initial values */
  80. hwif->index = index;
  81. hwif->major = ide_hwif_to_major[index];
  82. hwif->name[0] = 'i';
  83. hwif->name[1] = 'd';
  84. hwif->name[2] = 'e';
  85. hwif->name[3] = '0' + index;
  86. init_completion(&hwif->gendev_rel_comp);
  87. hwif->tp_ops = &default_tp_ops;
  88. ide_port_init_devices_data(hwif);
  89. }
  90. static void ide_port_init_devices_data(ide_hwif_t *hwif)
  91. {
  92. int unit;
  93. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  94. ide_drive_t *drive = &hwif->drives[unit];
  95. u8 j = (hwif->index * MAX_DRIVES) + unit;
  96. memset(drive, 0, sizeof(*drive));
  97. drive->media = ide_disk;
  98. drive->select = (unit << 4) | ATA_DEVICE_OBS;
  99. drive->hwif = hwif;
  100. drive->ready_stat = ATA_DRDY;
  101. drive->bad_wstat = BAD_W_STAT;
  102. drive->special.b.recalibrate = 1;
  103. drive->special.b.set_geometry = 1;
  104. drive->name[0] = 'h';
  105. drive->name[1] = 'd';
  106. drive->name[2] = 'a' + j;
  107. drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
  108. INIT_LIST_HEAD(&drive->list);
  109. init_completion(&drive->gendev_rel_comp);
  110. }
  111. }
  112. /* Called with ide_lock held. */
  113. static void __ide_port_unregister_devices(ide_hwif_t *hwif)
  114. {
  115. int i;
  116. for (i = 0; i < MAX_DRIVES; i++) {
  117. ide_drive_t *drive = &hwif->drives[i];
  118. if (drive->dev_flags & IDE_DFLAG_PRESENT) {
  119. spin_unlock_irq(&ide_lock);
  120. device_unregister(&drive->gendev);
  121. wait_for_completion(&drive->gendev_rel_comp);
  122. spin_lock_irq(&ide_lock);
  123. }
  124. }
  125. }
  126. void ide_port_unregister_devices(ide_hwif_t *hwif)
  127. {
  128. mutex_lock(&ide_cfg_mtx);
  129. spin_lock_irq(&ide_lock);
  130. __ide_port_unregister_devices(hwif);
  131. hwif->present = 0;
  132. ide_port_init_devices_data(hwif);
  133. spin_unlock_irq(&ide_lock);
  134. mutex_unlock(&ide_cfg_mtx);
  135. }
  136. EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
  137. /**
  138. * ide_unregister - free an IDE interface
  139. * @hwif: IDE interface
  140. *
  141. * Perform the final unregister of an IDE interface. At the moment
  142. * we don't refcount interfaces so this will also get split up.
  143. *
  144. * Locking:
  145. * The caller must not hold the IDE locks
  146. * The drive present/vanishing is not yet properly locked
  147. * Take care with the callbacks. These have been split to avoid
  148. * deadlocking the IDE layer. The shutdown callback is called
  149. * before we take the lock and free resources. It is up to the
  150. * caller to be sure there is no pending I/O here, and that
  151. * the interface will not be reopened (present/vanishing locking
  152. * isn't yet done BTW). After we commit to the final kill we
  153. * call the cleanup callback with the ide locks held.
  154. *
  155. * Unregister restores the hwif structures to the default state.
  156. * This is raving bonkers.
  157. */
  158. void ide_unregister(ide_hwif_t *hwif)
  159. {
  160. ide_hwif_t *g;
  161. ide_hwgroup_t *hwgroup;
  162. int irq_count = 0;
  163. BUG_ON(in_interrupt());
  164. BUG_ON(irqs_disabled());
  165. mutex_lock(&ide_cfg_mtx);
  166. spin_lock_irq(&ide_lock);
  167. if (hwif->present) {
  168. __ide_port_unregister_devices(hwif);
  169. hwif->present = 0;
  170. }
  171. spin_unlock_irq(&ide_lock);
  172. ide_proc_unregister_port(hwif);
  173. hwgroup = hwif->hwgroup;
  174. /*
  175. * free the irq if we were the only hwif using it
  176. */
  177. g = hwgroup->hwif;
  178. do {
  179. if (g->irq == hwif->irq)
  180. ++irq_count;
  181. g = g->next;
  182. } while (g != hwgroup->hwif);
  183. if (irq_count == 1)
  184. free_irq(hwif->irq, hwgroup);
  185. ide_remove_port_from_hwgroup(hwif);
  186. device_unregister(hwif->portdev);
  187. device_unregister(&hwif->gendev);
  188. wait_for_completion(&hwif->gendev_rel_comp);
  189. /*
  190. * Remove us from the kernel's knowledge
  191. */
  192. blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
  193. kfree(hwif->sg_table);
  194. unregister_blkdev(hwif->major, hwif->name);
  195. ide_release_dma_engine(hwif);
  196. mutex_unlock(&ide_cfg_mtx);
  197. }
  198. void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
  199. {
  200. memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports));
  201. hwif->irq = hw->irq;
  202. hwif->chipset = hw->chipset;
  203. hwif->dev = hw->dev;
  204. hwif->gendev.parent = hw->parent ? hw->parent : hw->dev;
  205. hwif->ack_intr = hw->ack_intr;
  206. hwif->config_data = hw->config;
  207. }
  208. /*
  209. * Locks for IDE setting functionality
  210. */
  211. DEFINE_MUTEX(ide_setting_mtx);
  212. ide_devset_get(io_32bit, io_32bit);
  213. static int set_io_32bit(ide_drive_t *drive, int arg)
  214. {
  215. if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT)
  216. return -EPERM;
  217. if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
  218. return -EINVAL;
  219. drive->io_32bit = arg;
  220. return 0;
  221. }
  222. ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS);
  223. static int set_ksettings(ide_drive_t *drive, int arg)
  224. {
  225. if (arg < 0 || arg > 1)
  226. return -EINVAL;
  227. if (arg)
  228. drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS;
  229. else
  230. drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS;
  231. return 0;
  232. }
  233. ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA);
  234. static int set_using_dma(ide_drive_t *drive, int arg)
  235. {
  236. #ifdef CONFIG_BLK_DEV_IDEDMA
  237. int err = -EPERM;
  238. if (arg < 0 || arg > 1)
  239. return -EINVAL;
  240. if (ata_id_has_dma(drive->id) == 0)
  241. goto out;
  242. if (drive->hwif->dma_ops == NULL)
  243. goto out;
  244. err = 0;
  245. if (arg) {
  246. if (ide_set_dma(drive))
  247. err = -EIO;
  248. } else
  249. ide_dma_off(drive);
  250. out:
  251. return err;
  252. #else
  253. if (arg < 0 || arg > 1)
  254. return -EINVAL;
  255. return -EPERM;
  256. #endif
  257. }
  258. /*
  259. * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
  260. */
  261. static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
  262. {
  263. switch (req_pio) {
  264. case 202:
  265. case 201:
  266. case 200:
  267. case 102:
  268. case 101:
  269. case 100:
  270. return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
  271. case 9:
  272. case 8:
  273. return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
  274. case 7:
  275. case 6:
  276. return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
  277. default:
  278. return 0;
  279. }
  280. }
  281. static int set_pio_mode(ide_drive_t *drive, int arg)
  282. {
  283. ide_hwif_t *hwif = drive->hwif;
  284. const struct ide_port_ops *port_ops = hwif->port_ops;
  285. if (arg < 0 || arg > 255)
  286. return -EINVAL;
  287. if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
  288. (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
  289. return -ENOSYS;
  290. if (set_pio_mode_abuse(drive->hwif, arg)) {
  291. if (arg == 8 || arg == 9) {
  292. unsigned long flags;
  293. /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
  294. spin_lock_irqsave(&ide_lock, flags);
  295. port_ops->set_pio_mode(drive, arg);
  296. spin_unlock_irqrestore(&ide_lock, flags);
  297. } else
  298. port_ops->set_pio_mode(drive, arg);
  299. } else {
  300. int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
  301. ide_set_pio(drive, arg);
  302. if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
  303. if (keep_dma)
  304. ide_dma_on(drive);
  305. }
  306. }
  307. return 0;
  308. }
  309. ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK);
  310. static int set_unmaskirq(ide_drive_t *drive, int arg)
  311. {
  312. if (drive->dev_flags & IDE_DFLAG_NO_UNMASK)
  313. return -EPERM;
  314. if (arg < 0 || arg > 1)
  315. return -EINVAL;
  316. if (arg)
  317. drive->dev_flags |= IDE_DFLAG_UNMASK;
  318. else
  319. drive->dev_flags &= ~IDE_DFLAG_UNMASK;
  320. return 0;
  321. }
  322. ide_ext_devset_rw_sync(io_32bit, io_32bit);
  323. ide_ext_devset_rw_sync(keepsettings, ksettings);
  324. ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
  325. ide_ext_devset_rw_sync(using_dma, using_dma);
  326. __IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
  327. static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
  328. {
  329. ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
  330. ide_hwif_t *hwif = HWIF(drive);
  331. struct request *rq;
  332. struct request_pm_state rqpm;
  333. ide_task_t args;
  334. int ret;
  335. /* call ACPI _GTM only once */
  336. if ((drive->dn & 1) == 0 || pair == NULL)
  337. ide_acpi_get_timing(hwif);
  338. memset(&rqpm, 0, sizeof(rqpm));
  339. memset(&args, 0, sizeof(args));
  340. rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
  341. rq->cmd_type = REQ_TYPE_PM_SUSPEND;
  342. rq->special = &args;
  343. rq->data = &rqpm;
  344. rqpm.pm_step = IDE_PM_START_SUSPEND;
  345. if (mesg.event == PM_EVENT_PRETHAW)
  346. mesg.event = PM_EVENT_FREEZE;
  347. rqpm.pm_state = mesg.event;
  348. ret = blk_execute_rq(drive->queue, NULL, rq, 0);
  349. blk_put_request(rq);
  350. /* call ACPI _PS3 only after both devices are suspended */
  351. if (ret == 0 && ((drive->dn & 1) || pair == NULL))
  352. ide_acpi_set_state(hwif, 0);
  353. return ret;
  354. }
  355. static int generic_ide_resume(struct device *dev)
  356. {
  357. ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
  358. ide_hwif_t *hwif = HWIF(drive);
  359. struct request *rq;
  360. struct request_pm_state rqpm;
  361. ide_task_t args;
  362. int err;
  363. /* call ACPI _PS0 / _STM only once */
  364. if ((drive->dn & 1) == 0 || pair == NULL) {
  365. ide_acpi_set_state(hwif, 1);
  366. ide_acpi_push_timing(hwif);
  367. }
  368. ide_acpi_exec_tfs(drive);
  369. memset(&rqpm, 0, sizeof(rqpm));
  370. memset(&args, 0, sizeof(args));
  371. rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
  372. rq->cmd_type = REQ_TYPE_PM_RESUME;
  373. rq->cmd_flags |= REQ_PREEMPT;
  374. rq->special = &args;
  375. rq->data = &rqpm;
  376. rqpm.pm_step = IDE_PM_START_RESUME;
  377. rqpm.pm_state = PM_EVENT_ON;
  378. err = blk_execute_rq(drive->queue, NULL, rq, 1);
  379. blk_put_request(rq);
  380. if (err == 0 && dev->driver) {
  381. ide_driver_t *drv = to_ide_driver(dev->driver);
  382. if (drv->resume)
  383. drv->resume(drive);
  384. }
  385. return err;
  386. }
  387. /**
  388. * ide_device_get - get an additional reference to a ide_drive_t
  389. * @drive: device to get a reference to
  390. *
  391. * Gets a reference to the ide_drive_t and increments the use count of the
  392. * underlying LLDD module.
  393. */
  394. int ide_device_get(ide_drive_t *drive)
  395. {
  396. struct device *host_dev;
  397. struct module *module;
  398. if (!get_device(&drive->gendev))
  399. return -ENXIO;
  400. host_dev = drive->hwif->host->dev[0];
  401. module = host_dev ? host_dev->driver->owner : NULL;
  402. if (module && !try_module_get(module)) {
  403. put_device(&drive->gendev);
  404. return -ENXIO;
  405. }
  406. return 0;
  407. }
  408. EXPORT_SYMBOL_GPL(ide_device_get);
  409. /**
  410. * ide_device_put - release a reference to a ide_drive_t
  411. * @drive: device to release a reference on
  412. *
  413. * Release a reference to the ide_drive_t and decrements the use count of
  414. * the underlying LLDD module.
  415. */
  416. void ide_device_put(ide_drive_t *drive)
  417. {
  418. #ifdef CONFIG_MODULE_UNLOAD
  419. struct device *host_dev = drive->hwif->host->dev[0];
  420. struct module *module = host_dev ? host_dev->driver->owner : NULL;
  421. if (module)
  422. module_put(module);
  423. #endif
  424. put_device(&drive->gendev);
  425. }
  426. EXPORT_SYMBOL_GPL(ide_device_put);
  427. static int ide_bus_match(struct device *dev, struct device_driver *drv)
  428. {
  429. return 1;
  430. }
  431. static char *media_string(ide_drive_t *drive)
  432. {
  433. switch (drive->media) {
  434. case ide_disk:
  435. return "disk";
  436. case ide_cdrom:
  437. return "cdrom";
  438. case ide_tape:
  439. return "tape";
  440. case ide_floppy:
  441. return "floppy";
  442. case ide_optical:
  443. return "optical";
  444. default:
  445. return "UNKNOWN";
  446. }
  447. }
  448. static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
  449. {
  450. ide_drive_t *drive = to_ide_device(dev);
  451. return sprintf(buf, "%s\n", media_string(drive));
  452. }
  453. static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
  454. {
  455. ide_drive_t *drive = to_ide_device(dev);
  456. return sprintf(buf, "%s\n", drive->name);
  457. }
  458. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
  459. {
  460. ide_drive_t *drive = to_ide_device(dev);
  461. return sprintf(buf, "ide:m-%s\n", media_string(drive));
  462. }
  463. static ssize_t model_show(struct device *dev, struct device_attribute *attr,
  464. char *buf)
  465. {
  466. ide_drive_t *drive = to_ide_device(dev);
  467. return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
  468. }
  469. static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
  470. char *buf)
  471. {
  472. ide_drive_t *drive = to_ide_device(dev);
  473. return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_FW_REV]);
  474. }
  475. static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
  476. char *buf)
  477. {
  478. ide_drive_t *drive = to_ide_device(dev);
  479. return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
  480. }
  481. static struct device_attribute ide_dev_attrs[] = {
  482. __ATTR_RO(media),
  483. __ATTR_RO(drivename),
  484. __ATTR_RO(modalias),
  485. __ATTR_RO(model),
  486. __ATTR_RO(firmware),
  487. __ATTR(serial, 0400, serial_show, NULL),
  488. __ATTR(unload_heads, 0644, ide_park_show, ide_park_store),
  489. __ATTR_NULL
  490. };
  491. static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
  492. {
  493. ide_drive_t *drive = to_ide_device(dev);
  494. add_uevent_var(env, "MEDIA=%s", media_string(drive));
  495. add_uevent_var(env, "DRIVENAME=%s", drive->name);
  496. add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive));
  497. return 0;
  498. }
  499. static int generic_ide_probe(struct device *dev)
  500. {
  501. ide_drive_t *drive = to_ide_device(dev);
  502. ide_driver_t *drv = to_ide_driver(dev->driver);
  503. return drv->probe ? drv->probe(drive) : -ENODEV;
  504. }
  505. static int generic_ide_remove(struct device *dev)
  506. {
  507. ide_drive_t *drive = to_ide_device(dev);
  508. ide_driver_t *drv = to_ide_driver(dev->driver);
  509. if (drv->remove)
  510. drv->remove(drive);
  511. return 0;
  512. }
  513. static void generic_ide_shutdown(struct device *dev)
  514. {
  515. ide_drive_t *drive = to_ide_device(dev);
  516. ide_driver_t *drv = to_ide_driver(dev->driver);
  517. if (dev->driver && drv->shutdown)
  518. drv->shutdown(drive);
  519. }
  520. struct bus_type ide_bus_type = {
  521. .name = "ide",
  522. .match = ide_bus_match,
  523. .uevent = ide_uevent,
  524. .probe = generic_ide_probe,
  525. .remove = generic_ide_remove,
  526. .shutdown = generic_ide_shutdown,
  527. .dev_attrs = ide_dev_attrs,
  528. .suspend = generic_ide_suspend,
  529. .resume = generic_ide_resume,
  530. };
  531. EXPORT_SYMBOL_GPL(ide_bus_type);
  532. int ide_vlb_clk;
  533. EXPORT_SYMBOL_GPL(ide_vlb_clk);
  534. module_param_named(vlb_clock, ide_vlb_clk, int, 0);
  535. MODULE_PARM_DESC(vlb_clock, "VLB clock frequency (in MHz)");
  536. int ide_pci_clk;
  537. EXPORT_SYMBOL_GPL(ide_pci_clk);
  538. module_param_named(pci_clock, ide_pci_clk, int, 0);
  539. MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)");
  540. static int ide_set_dev_param_mask(const char *s, struct kernel_param *kp)
  541. {
  542. int a, b, i, j = 1;
  543. unsigned int *dev_param_mask = (unsigned int *)kp->arg;
  544. if (sscanf(s, "%d.%d:%d", &a, &b, &j) != 3 &&
  545. sscanf(s, "%d.%d", &a, &b) != 2)
  546. return -EINVAL;
  547. i = a * MAX_DRIVES + b;
  548. if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
  549. return -EINVAL;
  550. if (j)
  551. *dev_param_mask |= (1 << i);
  552. else
  553. *dev_param_mask &= (1 << i);
  554. return 0;
  555. }
  556. static unsigned int ide_nodma;
  557. module_param_call(nodma, ide_set_dev_param_mask, NULL, &ide_nodma, 0);
  558. MODULE_PARM_DESC(nodma, "disallow DMA for a device");
  559. static unsigned int ide_noflush;
  560. module_param_call(noflush, ide_set_dev_param_mask, NULL, &ide_noflush, 0);
  561. MODULE_PARM_DESC(noflush, "disable flush requests for a device");
  562. static unsigned int ide_noprobe;
  563. module_param_call(noprobe, ide_set_dev_param_mask, NULL, &ide_noprobe, 0);
  564. MODULE_PARM_DESC(noprobe, "skip probing for a device");
  565. static unsigned int ide_nowerr;
  566. module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0);
  567. MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device");
  568. static unsigned int ide_cdroms;
  569. module_param_call(cdrom, ide_set_dev_param_mask, NULL, &ide_cdroms, 0);
  570. MODULE_PARM_DESC(cdrom, "force device as a CD-ROM");
  571. struct chs_geom {
  572. unsigned int cyl;
  573. u8 head;
  574. u8 sect;
  575. };
  576. static unsigned int ide_disks;
  577. static struct chs_geom ide_disks_chs[MAX_HWIFS * MAX_DRIVES];
  578. static int ide_set_disk_chs(const char *str, struct kernel_param *kp)
  579. {
  580. int a, b, c = 0, h = 0, s = 0, i, j = 1;
  581. if (sscanf(str, "%d.%d:%d,%d,%d", &a, &b, &c, &h, &s) != 5 &&
  582. sscanf(str, "%d.%d:%d", &a, &b, &j) != 3)
  583. return -EINVAL;
  584. i = a * MAX_DRIVES + b;
  585. if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
  586. return -EINVAL;
  587. if (c > INT_MAX || h > 255 || s > 255)
  588. return -EINVAL;
  589. if (j)
  590. ide_disks |= (1 << i);
  591. else
  592. ide_disks &= (1 << i);
  593. ide_disks_chs[i].cyl = c;
  594. ide_disks_chs[i].head = h;
  595. ide_disks_chs[i].sect = s;
  596. return 0;
  597. }
  598. module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0);
  599. MODULE_PARM_DESC(chs, "force device as a disk (using CHS)");
  600. static void ide_dev_apply_params(ide_drive_t *drive, u8 unit)
  601. {
  602. int i = drive->hwif->index * MAX_DRIVES + unit;
  603. if (ide_nodma & (1 << i)) {
  604. printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
  605. drive->dev_flags |= IDE_DFLAG_NODMA;
  606. }
  607. if (ide_noflush & (1 << i)) {
  608. printk(KERN_INFO "ide: disabling flush requests for %s\n",
  609. drive->name);
  610. drive->dev_flags |= IDE_DFLAG_NOFLUSH;
  611. }
  612. if (ide_noprobe & (1 << i)) {
  613. printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
  614. drive->dev_flags |= IDE_DFLAG_NOPROBE;
  615. }
  616. if (ide_nowerr & (1 << i)) {
  617. printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
  618. drive->name);
  619. drive->bad_wstat = BAD_R_STAT;
  620. }
  621. if (ide_cdroms & (1 << i)) {
  622. printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name);
  623. drive->dev_flags |= IDE_DFLAG_PRESENT;
  624. drive->media = ide_cdrom;
  625. /* an ATAPI device ignores DRDY */
  626. drive->ready_stat = 0;
  627. }
  628. if (ide_disks & (1 << i)) {
  629. drive->cyl = drive->bios_cyl = ide_disks_chs[i].cyl;
  630. drive->head = drive->bios_head = ide_disks_chs[i].head;
  631. drive->sect = drive->bios_sect = ide_disks_chs[i].sect;
  632. printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n",
  633. drive->name,
  634. drive->cyl, drive->head, drive->sect);
  635. drive->dev_flags |= IDE_DFLAG_FORCED_GEOM | IDE_DFLAG_PRESENT;
  636. drive->media = ide_disk;
  637. drive->ready_stat = ATA_DRDY;
  638. }
  639. }
  640. static unsigned int ide_ignore_cable;
  641. static int ide_set_ignore_cable(const char *s, struct kernel_param *kp)
  642. {
  643. int i, j = 1;
  644. if (sscanf(s, "%d:%d", &i, &j) != 2 && sscanf(s, "%d", &i) != 1)
  645. return -EINVAL;
  646. if (i >= MAX_HWIFS || j < 0 || j > 1)
  647. return -EINVAL;
  648. if (j)
  649. ide_ignore_cable |= (1 << i);
  650. else
  651. ide_ignore_cable &= (1 << i);
  652. return 0;
  653. }
  654. module_param_call(ignore_cable, ide_set_ignore_cable, NULL, NULL, 0);
  655. MODULE_PARM_DESC(ignore_cable, "ignore cable detection");
  656. void ide_port_apply_params(ide_hwif_t *hwif)
  657. {
  658. int i;
  659. if (ide_ignore_cable & (1 << hwif->index)) {
  660. printk(KERN_INFO "ide: ignoring cable detection for %s\n",
  661. hwif->name);
  662. hwif->cbl = ATA_CBL_PATA40_SHORT;
  663. }
  664. for (i = 0; i < MAX_DRIVES; i++)
  665. ide_dev_apply_params(&hwif->drives[i], i);
  666. }
  667. /*
  668. * This is gets invoked once during initialization, to set *everything* up
  669. */
  670. static int __init ide_init(void)
  671. {
  672. int ret;
  673. printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
  674. ret = bus_register(&ide_bus_type);
  675. if (ret < 0) {
  676. printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
  677. return ret;
  678. }
  679. ide_port_class = class_create(THIS_MODULE, "ide_port");
  680. if (IS_ERR(ide_port_class)) {
  681. ret = PTR_ERR(ide_port_class);
  682. goto out_port_class;
  683. }
  684. proc_ide_create();
  685. return 0;
  686. out_port_class:
  687. bus_unregister(&ide_bus_type);
  688. return ret;
  689. }
  690. static void __exit ide_exit(void)
  691. {
  692. proc_ide_destroy();
  693. class_destroy(ide_port_class);
  694. bus_unregister(&ide_bus_type);
  695. }
  696. module_init(ide_init);
  697. module_exit(ide_exit);
  698. MODULE_LICENSE("GPL");