ide.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  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. goto abort;
  279. __ide_port_unregister_devices(hwif);
  280. hwif->present = 0;
  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. spin_lock_irq(&ide_lock);
  306. if (hwif->dma_base)
  307. ide_release_dma_engine(hwif);
  308. /* restore hwif data to pristine status */
  309. ide_init_port_data(hwif, hwif->index);
  310. abort:
  311. spin_unlock_irq(&ide_lock);
  312. mutex_unlock(&ide_cfg_mtx);
  313. }
  314. EXPORT_SYMBOL(ide_unregister);
  315. void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
  316. {
  317. memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports));
  318. hwif->irq = hw->irq;
  319. hwif->chipset = hw->chipset;
  320. hwif->gendev.parent = hw->dev;
  321. hwif->ack_intr = hw->ack_intr;
  322. }
  323. EXPORT_SYMBOL_GPL(ide_init_port_hw);
  324. /*
  325. * Locks for IDE setting functionality
  326. */
  327. DEFINE_MUTEX(ide_setting_mtx);
  328. EXPORT_SYMBOL_GPL(ide_setting_mtx);
  329. /**
  330. * ide_spin_wait_hwgroup - wait for group
  331. * @drive: drive in the group
  332. *
  333. * Wait for an IDE device group to go non busy and then return
  334. * holding the ide_lock which guards the hwgroup->busy status
  335. * and right to use it.
  336. */
  337. int ide_spin_wait_hwgroup (ide_drive_t *drive)
  338. {
  339. ide_hwgroup_t *hwgroup = HWGROUP(drive);
  340. unsigned long timeout = jiffies + (3 * HZ);
  341. spin_lock_irq(&ide_lock);
  342. while (hwgroup->busy) {
  343. unsigned long lflags;
  344. spin_unlock_irq(&ide_lock);
  345. local_irq_set(lflags);
  346. if (time_after(jiffies, timeout)) {
  347. local_irq_restore(lflags);
  348. printk(KERN_ERR "%s: channel busy\n", drive->name);
  349. return -EBUSY;
  350. }
  351. local_irq_restore(lflags);
  352. spin_lock_irq(&ide_lock);
  353. }
  354. return 0;
  355. }
  356. EXPORT_SYMBOL(ide_spin_wait_hwgroup);
  357. int set_io_32bit(ide_drive_t *drive, int arg)
  358. {
  359. if (drive->no_io_32bit)
  360. return -EPERM;
  361. if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
  362. return -EINVAL;
  363. if (ide_spin_wait_hwgroup(drive))
  364. return -EBUSY;
  365. drive->io_32bit = arg;
  366. spin_unlock_irq(&ide_lock);
  367. return 0;
  368. }
  369. static int set_ksettings(ide_drive_t *drive, int arg)
  370. {
  371. if (arg < 0 || arg > 1)
  372. return -EINVAL;
  373. if (ide_spin_wait_hwgroup(drive))
  374. return -EBUSY;
  375. drive->keep_settings = arg;
  376. spin_unlock_irq(&ide_lock);
  377. return 0;
  378. }
  379. int set_using_dma(ide_drive_t *drive, int arg)
  380. {
  381. #ifdef CONFIG_BLK_DEV_IDEDMA
  382. ide_hwif_t *hwif = drive->hwif;
  383. int err = -EPERM;
  384. if (arg < 0 || arg > 1)
  385. return -EINVAL;
  386. if (!drive->id || !(drive->id->capability & 1))
  387. goto out;
  388. if (hwif->dma_ops == NULL)
  389. goto out;
  390. err = -EBUSY;
  391. if (ide_spin_wait_hwgroup(drive))
  392. goto out;
  393. /*
  394. * set ->busy flag, unlock and let it ride
  395. */
  396. hwif->hwgroup->busy = 1;
  397. spin_unlock_irq(&ide_lock);
  398. err = 0;
  399. if (arg) {
  400. if (ide_set_dma(drive))
  401. err = -EIO;
  402. } else
  403. ide_dma_off(drive);
  404. /*
  405. * lock, clear ->busy flag and unlock before leaving
  406. */
  407. spin_lock_irq(&ide_lock);
  408. hwif->hwgroup->busy = 0;
  409. spin_unlock_irq(&ide_lock);
  410. out:
  411. return err;
  412. #else
  413. if (arg < 0 || arg > 1)
  414. return -EINVAL;
  415. return -EPERM;
  416. #endif
  417. }
  418. int set_pio_mode(ide_drive_t *drive, int arg)
  419. {
  420. struct request rq;
  421. ide_hwif_t *hwif = drive->hwif;
  422. const struct ide_port_ops *port_ops = hwif->port_ops;
  423. if (arg < 0 || arg > 255)
  424. return -EINVAL;
  425. if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
  426. (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
  427. return -ENOSYS;
  428. if (drive->special.b.set_tune)
  429. return -EBUSY;
  430. ide_init_drive_cmd(&rq);
  431. rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
  432. drive->tune_req = (u8) arg;
  433. drive->special.b.set_tune = 1;
  434. (void) ide_do_drive_cmd(drive, &rq, ide_wait);
  435. return 0;
  436. }
  437. static int set_unmaskirq(ide_drive_t *drive, int arg)
  438. {
  439. if (drive->no_unmask)
  440. return -EPERM;
  441. if (arg < 0 || arg > 1)
  442. return -EINVAL;
  443. if (ide_spin_wait_hwgroup(drive))
  444. return -EBUSY;
  445. drive->unmask = arg;
  446. spin_unlock_irq(&ide_lock);
  447. return 0;
  448. }
  449. /**
  450. * system_bus_clock - clock guess
  451. *
  452. * External version of the bus clock guess used by very old IDE drivers
  453. * for things like VLB timings. Should not be used.
  454. */
  455. int system_bus_clock (void)
  456. {
  457. return system_bus_speed;
  458. }
  459. EXPORT_SYMBOL(system_bus_clock);
  460. static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
  461. {
  462. ide_drive_t *drive = dev->driver_data;
  463. ide_hwif_t *hwif = HWIF(drive);
  464. struct request rq;
  465. struct request_pm_state rqpm;
  466. ide_task_t args;
  467. int ret;
  468. /* Call ACPI _GTM only once */
  469. if (!(drive->dn % 2))
  470. ide_acpi_get_timing(hwif);
  471. blk_rq_init(NULL, &rq);
  472. memset(&rqpm, 0, sizeof(rqpm));
  473. memset(&args, 0, sizeof(args));
  474. rq.cmd_type = REQ_TYPE_PM_SUSPEND;
  475. rq.special = &args;
  476. rq.data = &rqpm;
  477. rqpm.pm_step = ide_pm_state_start_suspend;
  478. if (mesg.event == PM_EVENT_PRETHAW)
  479. mesg.event = PM_EVENT_FREEZE;
  480. rqpm.pm_state = mesg.event;
  481. ret = ide_do_drive_cmd(drive, &rq, ide_wait);
  482. /* only call ACPI _PS3 after both drivers are suspended */
  483. if (!ret && (((drive->dn % 2) && hwif->drives[0].present
  484. && hwif->drives[1].present)
  485. || !hwif->drives[0].present
  486. || !hwif->drives[1].present))
  487. ide_acpi_set_state(hwif, 0);
  488. return ret;
  489. }
  490. static int generic_ide_resume(struct device *dev)
  491. {
  492. ide_drive_t *drive = dev->driver_data;
  493. ide_hwif_t *hwif = HWIF(drive);
  494. struct request rq;
  495. struct request_pm_state rqpm;
  496. ide_task_t args;
  497. int err;
  498. /* Call ACPI _STM only once */
  499. if (!(drive->dn % 2)) {
  500. ide_acpi_set_state(hwif, 1);
  501. ide_acpi_push_timing(hwif);
  502. }
  503. ide_acpi_exec_tfs(drive);
  504. blk_rq_init(NULL, &rq);
  505. memset(&rqpm, 0, sizeof(rqpm));
  506. memset(&args, 0, sizeof(args));
  507. rq.cmd_type = REQ_TYPE_PM_RESUME;
  508. rq.special = &args;
  509. rq.data = &rqpm;
  510. rqpm.pm_step = ide_pm_state_start_resume;
  511. rqpm.pm_state = PM_EVENT_ON;
  512. err = ide_do_drive_cmd(drive, &rq, ide_head_wait);
  513. if (err == 0 && dev->driver) {
  514. ide_driver_t *drv = to_ide_driver(dev->driver);
  515. if (drv->resume)
  516. drv->resume(drive);
  517. }
  518. return err;
  519. }
  520. int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
  521. unsigned int cmd, unsigned long arg)
  522. {
  523. unsigned long flags;
  524. ide_driver_t *drv;
  525. void __user *p = (void __user *)arg;
  526. int err = 0, (*setfunc)(ide_drive_t *, int);
  527. u8 *val;
  528. switch (cmd) {
  529. case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val;
  530. case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
  531. case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val;
  532. case HDIO_GET_DMA: val = &drive->using_dma; goto read_val;
  533. case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val;
  534. case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val;
  535. case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val;
  536. case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val;
  537. case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val;
  538. }
  539. switch (cmd) {
  540. case HDIO_OBSOLETE_IDENTITY:
  541. case HDIO_GET_IDENTITY:
  542. if (bdev != bdev->bd_contains)
  543. return -EINVAL;
  544. if (drive->id_read == 0)
  545. return -ENOMSG;
  546. if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
  547. return -EFAULT;
  548. return 0;
  549. case HDIO_GET_NICE:
  550. return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
  551. drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
  552. drive->nice1 << IDE_NICE_1,
  553. (long __user *) arg);
  554. #ifdef CONFIG_IDE_TASK_IOCTL
  555. case HDIO_DRIVE_TASKFILE:
  556. if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
  557. return -EACCES;
  558. switch(drive->media) {
  559. case ide_disk:
  560. return ide_taskfile_ioctl(drive, cmd, arg);
  561. default:
  562. return -ENOMSG;
  563. }
  564. #endif /* CONFIG_IDE_TASK_IOCTL */
  565. case HDIO_DRIVE_CMD:
  566. if (!capable(CAP_SYS_RAWIO))
  567. return -EACCES;
  568. return ide_cmd_ioctl(drive, cmd, arg);
  569. case HDIO_DRIVE_TASK:
  570. if (!capable(CAP_SYS_RAWIO))
  571. return -EACCES;
  572. return ide_task_ioctl(drive, cmd, arg);
  573. case HDIO_SET_NICE:
  574. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  575. if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
  576. return -EPERM;
  577. drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
  578. drv = *(ide_driver_t **)bdev->bd_disk->private_data;
  579. if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
  580. drive->dsc_overlap = 0;
  581. return -EPERM;
  582. }
  583. drive->nice1 = (arg >> IDE_NICE_1) & 1;
  584. return 0;
  585. case HDIO_DRIVE_RESET:
  586. if (!capable(CAP_SYS_ADMIN))
  587. return -EACCES;
  588. /*
  589. * Abort the current command on the
  590. * group if there is one, taking
  591. * care not to allow anything else
  592. * to be queued and to die on the
  593. * spot if we miss one somehow
  594. */
  595. spin_lock_irqsave(&ide_lock, flags);
  596. if (HWGROUP(drive)->resetting) {
  597. spin_unlock_irqrestore(&ide_lock, flags);
  598. return -EBUSY;
  599. }
  600. ide_abort(drive, "drive reset");
  601. BUG_ON(HWGROUP(drive)->handler);
  602. /* Ensure nothing gets queued after we
  603. drop the lock. Reset will clear the busy */
  604. HWGROUP(drive)->busy = 1;
  605. spin_unlock_irqrestore(&ide_lock, flags);
  606. (void) ide_do_reset(drive);
  607. return 0;
  608. case HDIO_GET_BUSSTATE:
  609. if (!capable(CAP_SYS_ADMIN))
  610. return -EACCES;
  611. if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
  612. return -EFAULT;
  613. return 0;
  614. case HDIO_SET_BUSSTATE:
  615. if (!capable(CAP_SYS_ADMIN))
  616. return -EACCES;
  617. return -EOPNOTSUPP;
  618. default:
  619. return -EINVAL;
  620. }
  621. read_val:
  622. mutex_lock(&ide_setting_mtx);
  623. spin_lock_irqsave(&ide_lock, flags);
  624. err = *val;
  625. spin_unlock_irqrestore(&ide_lock, flags);
  626. mutex_unlock(&ide_setting_mtx);
  627. return err >= 0 ? put_user(err, (long __user *)arg) : err;
  628. set_val:
  629. if (bdev != bdev->bd_contains)
  630. err = -EINVAL;
  631. else {
  632. if (!capable(CAP_SYS_ADMIN))
  633. err = -EACCES;
  634. else {
  635. mutex_lock(&ide_setting_mtx);
  636. err = setfunc(drive, arg);
  637. mutex_unlock(&ide_setting_mtx);
  638. }
  639. }
  640. return err;
  641. }
  642. EXPORT_SYMBOL(generic_ide_ioctl);
  643. /*
  644. * stridx() returns the offset of c within s,
  645. * or -1 if c is '\0' or not found within s.
  646. */
  647. static int __init stridx (const char *s, char c)
  648. {
  649. char *i = strchr(s, c);
  650. return (i && c) ? i - s : -1;
  651. }
  652. /*
  653. * match_parm() does parsing for ide_setup():
  654. *
  655. * 1. the first char of s must be '='.
  656. * 2. if the remainder matches one of the supplied keywords,
  657. * the index (1 based) of the keyword is negated and returned.
  658. * 3. if the remainder is a series of no more than max_vals numbers
  659. * separated by commas, the numbers are saved in vals[] and a
  660. * count of how many were saved is returned. Base10 is assumed,
  661. * and base16 is allowed when prefixed with "0x".
  662. * 4. otherwise, zero is returned.
  663. */
  664. static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
  665. {
  666. static const char *decimal = "0123456789";
  667. static const char *hex = "0123456789abcdef";
  668. int i, n;
  669. if (*s++ == '=') {
  670. /*
  671. * Try matching against the supplied keywords,
  672. * and return -(index+1) if we match one
  673. */
  674. if (keywords != NULL) {
  675. for (i = 0; *keywords != NULL; ++i) {
  676. if (!strcmp(s, *keywords++))
  677. return -(i+1);
  678. }
  679. }
  680. /*
  681. * Look for a series of no more than "max_vals"
  682. * numeric values separated by commas, in base10,
  683. * or base16 when prefixed with "0x".
  684. * Return a count of how many were found.
  685. */
  686. for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
  687. vals[n] = i;
  688. while ((i = stridx(decimal, *++s)) >= 0)
  689. vals[n] = (vals[n] * 10) + i;
  690. if (*s == 'x' && !vals[n]) {
  691. while ((i = stridx(hex, *++s)) >= 0)
  692. vals[n] = (vals[n] * 0x10) + i;
  693. }
  694. if (++n == max_vals)
  695. break;
  696. if (*s == ',' || *s == ';')
  697. ++s;
  698. }
  699. if (!*s)
  700. return n;
  701. }
  702. return 0; /* zero = nothing matched */
  703. }
  704. /*
  705. * ide_setup() gets called VERY EARLY during initialization,
  706. * to handle kernel "command line" strings beginning with "hdx=" or "ide".
  707. *
  708. * Remember to update Documentation/ide/ide.txt if you change something here.
  709. */
  710. static int __init ide_setup(char *s)
  711. {
  712. ide_hwif_t *hwif;
  713. ide_drive_t *drive;
  714. unsigned int hw, unit;
  715. int vals[3];
  716. const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
  717. if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
  718. return 0; /* driver and not us */
  719. if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
  720. return 0;
  721. printk(KERN_INFO "ide_setup: %s", s);
  722. init_ide_data ();
  723. #ifdef CONFIG_BLK_DEV_IDEDOUBLER
  724. if (!strcmp(s, "ide=doubler")) {
  725. extern int ide_doubler;
  726. printk(" : Enabled support for IDE doublers\n");
  727. ide_doubler = 1;
  728. goto obsolete_option;
  729. }
  730. #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
  731. if (!strcmp(s, "ide=nodma")) {
  732. printk(" : Prevented DMA\n");
  733. noautodma = 1;
  734. goto obsolete_option;
  735. }
  736. #ifdef CONFIG_BLK_DEV_IDEACPI
  737. if (!strcmp(s, "ide=noacpi")) {
  738. //printk(" : Disable IDE ACPI support.\n");
  739. ide_noacpi = 1;
  740. goto obsolete_option;
  741. }
  742. if (!strcmp(s, "ide=acpigtf")) {
  743. //printk(" : Enable IDE ACPI _GTF support.\n");
  744. ide_acpigtf = 1;
  745. goto obsolete_option;
  746. }
  747. if (!strcmp(s, "ide=acpionboot")) {
  748. //printk(" : Call IDE ACPI methods on boot.\n");
  749. ide_acpionboot = 1;
  750. goto obsolete_option;
  751. }
  752. #endif /* CONFIG_BLK_DEV_IDEACPI */
  753. /*
  754. * Look for drive options: "hdx="
  755. */
  756. if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
  757. const char *hd_words[] = {
  758. "none", "noprobe", "nowerr", "cdrom", "nodma",
  759. "-6", "-7", "-8", "-9", "-10",
  760. "noflush", "remap", "remap63", "scsi", NULL };
  761. unit = s[2] - 'a';
  762. hw = unit / MAX_DRIVES;
  763. unit = unit % MAX_DRIVES;
  764. hwif = &ide_hwifs[hw];
  765. drive = &hwif->drives[unit];
  766. if (strncmp(s + 4, "ide-", 4) == 0) {
  767. strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
  768. goto obsolete_option;
  769. }
  770. switch (match_parm(&s[3], hd_words, vals, 3)) {
  771. case -1: /* "none" */
  772. case -2: /* "noprobe" */
  773. drive->noprobe = 1;
  774. goto obsolete_option;
  775. case -3: /* "nowerr" */
  776. drive->bad_wstat = BAD_R_STAT;
  777. goto obsolete_option;
  778. case -4: /* "cdrom" */
  779. drive->present = 1;
  780. drive->media = ide_cdrom;
  781. /* an ATAPI device ignores DRDY */
  782. drive->ready_stat = 0;
  783. goto obsolete_option;
  784. case -5: /* nodma */
  785. drive->nodma = 1;
  786. goto obsolete_option;
  787. case -11: /* noflush */
  788. drive->noflush = 1;
  789. goto obsolete_option;
  790. case -12: /* "remap" */
  791. drive->remap_0_to_1 = 1;
  792. goto obsolete_option;
  793. case -13: /* "remap63" */
  794. drive->sect0 = 63;
  795. goto obsolete_option;
  796. case -14: /* "scsi" */
  797. drive->scsi = 1;
  798. goto obsolete_option;
  799. case 3: /* cyl,head,sect */
  800. drive->media = ide_disk;
  801. drive->ready_stat = READY_STAT;
  802. drive->cyl = drive->bios_cyl = vals[0];
  803. drive->head = drive->bios_head = vals[1];
  804. drive->sect = drive->bios_sect = vals[2];
  805. drive->present = 1;
  806. drive->forced_geom = 1;
  807. goto obsolete_option;
  808. default:
  809. goto bad_option;
  810. }
  811. }
  812. if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
  813. goto bad_option;
  814. /*
  815. * Look for bus speed option: "idebus="
  816. */
  817. if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
  818. if (match_parm(&s[6], NULL, vals, 1) != 1)
  819. goto bad_option;
  820. if (vals[0] >= 20 && vals[0] <= 66) {
  821. idebus_parameter = vals[0];
  822. } else
  823. printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
  824. goto obsolete_option;
  825. }
  826. bad_option:
  827. printk(" -- BAD OPTION\n");
  828. return 1;
  829. obsolete_option:
  830. printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
  831. return 1;
  832. }
  833. EXPORT_SYMBOL(ide_lock);
  834. static int ide_bus_match(struct device *dev, struct device_driver *drv)
  835. {
  836. return 1;
  837. }
  838. static char *media_string(ide_drive_t *drive)
  839. {
  840. switch (drive->media) {
  841. case ide_disk:
  842. return "disk";
  843. case ide_cdrom:
  844. return "cdrom";
  845. case ide_tape:
  846. return "tape";
  847. case ide_floppy:
  848. return "floppy";
  849. case ide_optical:
  850. return "optical";
  851. default:
  852. return "UNKNOWN";
  853. }
  854. }
  855. static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
  856. {
  857. ide_drive_t *drive = to_ide_device(dev);
  858. return sprintf(buf, "%s\n", media_string(drive));
  859. }
  860. static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
  861. {
  862. ide_drive_t *drive = to_ide_device(dev);
  863. return sprintf(buf, "%s\n", drive->name);
  864. }
  865. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
  866. {
  867. ide_drive_t *drive = to_ide_device(dev);
  868. return sprintf(buf, "ide:m-%s\n", media_string(drive));
  869. }
  870. static ssize_t model_show(struct device *dev, struct device_attribute *attr,
  871. char *buf)
  872. {
  873. ide_drive_t *drive = to_ide_device(dev);
  874. return sprintf(buf, "%s\n", drive->id->model);
  875. }
  876. static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
  877. char *buf)
  878. {
  879. ide_drive_t *drive = to_ide_device(dev);
  880. return sprintf(buf, "%s\n", drive->id->fw_rev);
  881. }
  882. static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
  883. char *buf)
  884. {
  885. ide_drive_t *drive = to_ide_device(dev);
  886. return sprintf(buf, "%s\n", drive->id->serial_no);
  887. }
  888. static struct device_attribute ide_dev_attrs[] = {
  889. __ATTR_RO(media),
  890. __ATTR_RO(drivename),
  891. __ATTR_RO(modalias),
  892. __ATTR_RO(model),
  893. __ATTR_RO(firmware),
  894. __ATTR(serial, 0400, serial_show, NULL),
  895. __ATTR_NULL
  896. };
  897. static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
  898. {
  899. ide_drive_t *drive = to_ide_device(dev);
  900. add_uevent_var(env, "MEDIA=%s", media_string(drive));
  901. add_uevent_var(env, "DRIVENAME=%s", drive->name);
  902. add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive));
  903. return 0;
  904. }
  905. static int generic_ide_probe(struct device *dev)
  906. {
  907. ide_drive_t *drive = to_ide_device(dev);
  908. ide_driver_t *drv = to_ide_driver(dev->driver);
  909. return drv->probe ? drv->probe(drive) : -ENODEV;
  910. }
  911. static int generic_ide_remove(struct device *dev)
  912. {
  913. ide_drive_t *drive = to_ide_device(dev);
  914. ide_driver_t *drv = to_ide_driver(dev->driver);
  915. if (drv->remove)
  916. drv->remove(drive);
  917. return 0;
  918. }
  919. static void generic_ide_shutdown(struct device *dev)
  920. {
  921. ide_drive_t *drive = to_ide_device(dev);
  922. ide_driver_t *drv = to_ide_driver(dev->driver);
  923. if (dev->driver && drv->shutdown)
  924. drv->shutdown(drive);
  925. }
  926. struct bus_type ide_bus_type = {
  927. .name = "ide",
  928. .match = ide_bus_match,
  929. .uevent = ide_uevent,
  930. .probe = generic_ide_probe,
  931. .remove = generic_ide_remove,
  932. .shutdown = generic_ide_shutdown,
  933. .dev_attrs = ide_dev_attrs,
  934. .suspend = generic_ide_suspend,
  935. .resume = generic_ide_resume,
  936. };
  937. EXPORT_SYMBOL_GPL(ide_bus_type);
  938. static void ide_port_class_release(struct device *portdev)
  939. {
  940. ide_hwif_t *hwif = dev_get_drvdata(portdev);
  941. put_device(&hwif->gendev);
  942. }
  943. int ide_vlb_clk;
  944. EXPORT_SYMBOL_GPL(ide_vlb_clk);
  945. module_param_named(vlb_clock, ide_vlb_clk, int, 0);
  946. MODULE_PARM_DESC(vlb_clock, "VLB clock frequency (in MHz)");
  947. int ide_pci_clk;
  948. EXPORT_SYMBOL_GPL(ide_pci_clk);
  949. module_param_named(pci_clock, ide_pci_clk, int, 0);
  950. MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)");
  951. static int ide_set_dev_param_mask(const char *s, struct kernel_param *kp)
  952. {
  953. int a, b, i, j = 1;
  954. unsigned int *dev_param_mask = (unsigned int *)kp->arg;
  955. if (sscanf(s, "%d.%d:%d", &a, &b, &j) != 3 &&
  956. sscanf(s, "%d.%d", &a, &b) != 2)
  957. return -EINVAL;
  958. i = a * MAX_DRIVES + b;
  959. if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
  960. return -EINVAL;
  961. if (j)
  962. *dev_param_mask |= (1 << i);
  963. else
  964. *dev_param_mask &= (1 << i);
  965. return 0;
  966. }
  967. static unsigned int ide_nodma;
  968. module_param_call(nodma, ide_set_dev_param_mask, NULL, &ide_nodma, 0);
  969. MODULE_PARM_DESC(nodma, "disallow DMA for a device");
  970. static unsigned int ide_noflush;
  971. module_param_call(noflush, ide_set_dev_param_mask, NULL, &ide_noflush, 0);
  972. MODULE_PARM_DESC(noflush, "disable flush requests for a device");
  973. static unsigned int ide_noprobe;
  974. module_param_call(noprobe, ide_set_dev_param_mask, NULL, &ide_noprobe, 0);
  975. MODULE_PARM_DESC(noprobe, "skip probing for a device");
  976. static unsigned int ide_nowerr;
  977. module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0);
  978. MODULE_PARM_DESC(nowerr, "ignore the WRERR_STAT bit for a device");
  979. static unsigned int ide_cdroms;
  980. module_param_call(cdrom, ide_set_dev_param_mask, NULL, &ide_cdroms, 0);
  981. MODULE_PARM_DESC(cdrom, "force device as a CD-ROM");
  982. struct chs_geom {
  983. unsigned int cyl;
  984. u8 head;
  985. u8 sect;
  986. };
  987. static unsigned int ide_disks;
  988. static struct chs_geom ide_disks_chs[MAX_HWIFS * MAX_DRIVES];
  989. static int ide_set_disk_chs(const char *str, struct kernel_param *kp)
  990. {
  991. int a, b, c = 0, h = 0, s = 0, i, j = 1;
  992. if (sscanf(str, "%d.%d:%d,%d,%d", &a, &b, &c, &h, &s) != 5 &&
  993. sscanf(str, "%d.%d:%d", &a, &b, &j) != 3)
  994. return -EINVAL;
  995. i = a * MAX_DRIVES + b;
  996. if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
  997. return -EINVAL;
  998. if (c > INT_MAX || h > 255 || s > 255)
  999. return -EINVAL;
  1000. if (j)
  1001. ide_disks |= (1 << i);
  1002. else
  1003. ide_disks &= (1 << i);
  1004. ide_disks_chs[i].cyl = c;
  1005. ide_disks_chs[i].head = h;
  1006. ide_disks_chs[i].sect = s;
  1007. return 0;
  1008. }
  1009. module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0);
  1010. MODULE_PARM_DESC(chs, "force device as a disk (using CHS)");
  1011. static void ide_dev_apply_params(ide_drive_t *drive)
  1012. {
  1013. int i = drive->hwif->index * MAX_DRIVES + drive->select.b.unit;
  1014. if (ide_nodma & (1 << i)) {
  1015. printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
  1016. drive->nodma = 1;
  1017. }
  1018. if (ide_noflush & (1 << i)) {
  1019. printk(KERN_INFO "ide: disabling flush requests for %s\n",
  1020. drive->name);
  1021. drive->noflush = 1;
  1022. }
  1023. if (ide_noprobe & (1 << i)) {
  1024. printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
  1025. drive->noprobe = 1;
  1026. }
  1027. if (ide_nowerr & (1 << i)) {
  1028. printk(KERN_INFO "ide: ignoring the WRERR_STAT bit for %s\n",
  1029. drive->name);
  1030. drive->bad_wstat = BAD_R_STAT;
  1031. }
  1032. if (ide_cdroms & (1 << i)) {
  1033. printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name);
  1034. drive->present = 1;
  1035. drive->media = ide_cdrom;
  1036. /* an ATAPI device ignores DRDY */
  1037. drive->ready_stat = 0;
  1038. }
  1039. if (ide_disks & (1 << i)) {
  1040. drive->cyl = drive->bios_cyl = ide_disks_chs[i].cyl;
  1041. drive->head = drive->bios_head = ide_disks_chs[i].head;
  1042. drive->sect = drive->bios_sect = ide_disks_chs[i].sect;
  1043. drive->forced_geom = 1;
  1044. printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n",
  1045. drive->name,
  1046. drive->cyl, drive->head, drive->sect);
  1047. drive->present = 1;
  1048. drive->media = ide_disk;
  1049. drive->ready_stat = READY_STAT;
  1050. }
  1051. }
  1052. static unsigned int ide_ignore_cable;
  1053. static int ide_set_ignore_cable(const char *s, struct kernel_param *kp)
  1054. {
  1055. int i, j = 1;
  1056. if (sscanf(s, "%d:%d", &i, &j) != 2 && sscanf(s, "%d", &i) != 1)
  1057. return -EINVAL;
  1058. if (i >= MAX_HWIFS || j < 0 || j > 1)
  1059. return -EINVAL;
  1060. if (j)
  1061. ide_ignore_cable |= (1 << i);
  1062. else
  1063. ide_ignore_cable &= (1 << i);
  1064. return 0;
  1065. }
  1066. module_param_call(ignore_cable, ide_set_ignore_cable, NULL, NULL, 0);
  1067. MODULE_PARM_DESC(ignore_cable, "ignore cable detection");
  1068. void ide_port_apply_params(ide_hwif_t *hwif)
  1069. {
  1070. int i;
  1071. if (ide_ignore_cable & (1 << hwif->index)) {
  1072. printk(KERN_INFO "ide: ignoring cable detection for %s\n",
  1073. hwif->name);
  1074. hwif->cbl = ATA_CBL_PATA40_SHORT;
  1075. }
  1076. for (i = 0; i < MAX_DRIVES; i++)
  1077. ide_dev_apply_params(&hwif->drives[i]);
  1078. }
  1079. /*
  1080. * This is gets invoked once during initialization, to set *everything* up
  1081. */
  1082. static int __init ide_init(void)
  1083. {
  1084. int ret;
  1085. printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
  1086. system_bus_speed = ide_system_bus_speed();
  1087. printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
  1088. "for PIO modes%s\n", system_bus_speed,
  1089. idebus_parameter ? "" : "; override with idebus=xx");
  1090. ret = bus_register(&ide_bus_type);
  1091. if (ret < 0) {
  1092. printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
  1093. return ret;
  1094. }
  1095. ide_port_class = class_create(THIS_MODULE, "ide_port");
  1096. if (IS_ERR(ide_port_class)) {
  1097. ret = PTR_ERR(ide_port_class);
  1098. goto out_port_class;
  1099. }
  1100. ide_port_class->dev_release = ide_port_class_release;
  1101. init_ide_data();
  1102. proc_ide_create();
  1103. return 0;
  1104. out_port_class:
  1105. bus_unregister(&ide_bus_type);
  1106. return ret;
  1107. }
  1108. #ifdef MODULE
  1109. static char *options = NULL;
  1110. module_param(options, charp, 0);
  1111. MODULE_LICENSE("GPL");
  1112. static void __init parse_options (char *line)
  1113. {
  1114. char *next = line;
  1115. if (line == NULL || !*line)
  1116. return;
  1117. while ((line = next) != NULL) {
  1118. if ((next = strchr(line,' ')) != NULL)
  1119. *next++ = 0;
  1120. if (!ide_setup(line))
  1121. printk (KERN_INFO "Unknown option '%s'\n", line);
  1122. }
  1123. }
  1124. int __init init_module (void)
  1125. {
  1126. parse_options(options);
  1127. return ide_init();
  1128. }
  1129. void __exit cleanup_module (void)
  1130. {
  1131. proc_ide_destroy();
  1132. class_destroy(ide_port_class);
  1133. bus_unregister(&ide_bus_type);
  1134. }
  1135. #else /* !MODULE */
  1136. __setup("", ide_setup);
  1137. module_init(ide_init);
  1138. #endif /* MODULE */