ide.c 35 KB

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