ide.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  1. /*
  2. * linux/drivers/ide/ide.c Version 7.00beta2 Mar 05 2003
  3. *
  4. * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
  5. */
  6. /*
  7. * Mostly written by Mark Lord <mlord@pobox.com>
  8. * and Gadi Oxman <gadio@netvision.net.il>
  9. * and Andre Hedrick <andre@linux-ide.org>
  10. *
  11. * See linux/MAINTAINERS for address of current maintainer.
  12. *
  13. * This is the multiple IDE interface driver, as evolved from hd.c.
  14. * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs
  15. * (usually 14 & 15).
  16. * There can be up to two drives per interface, as per the ATA-2 spec.
  17. *
  18. * ...
  19. *
  20. * From hd.c:
  21. * |
  22. * | It traverses the request-list, using interrupts to jump between functions.
  23. * | As nearly all functions can be called within interrupts, we may not sleep.
  24. * | Special care is recommended. Have Fun!
  25. * |
  26. * | modified by Drew Eckhardt to check nr of hd's from the CMOS.
  27. * |
  28. * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
  29. * | in the early extended-partition checks and added DM partitions.
  30. * |
  31. * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
  32. * |
  33. * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
  34. * | and general streamlining by Mark Lord (mlord@pobox.com).
  35. *
  36. * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
  37. *
  38. * Mark Lord (mlord@pobox.com) (IDE Perf.Pkg)
  39. * Delman Lee (delman@ieee.org) ("Mr. atdisk2")
  40. * Scott Snyder (snyder@fnald0.fnal.gov) (ATAPI IDE cd-rom)
  41. *
  42. * This was a rewrite of just about everything from hd.c, though some original
  43. * code is still sprinkled about. Think of it as a major evolution, with
  44. * inspiration from lots of linux users, esp. hamish@zot.apana.org.au
  45. */
  46. #define REVISION "Revision: 7.00alpha2"
  47. #define VERSION "Id: ide.c 7.00a2 20020906"
  48. #define _IDE_C /* Tell ide.h it's really us */
  49. #include <linux/module.h>
  50. #include <linux/types.h>
  51. #include <linux/string.h>
  52. #include <linux/kernel.h>
  53. #include <linux/timer.h>
  54. #include <linux/mm.h>
  55. #include <linux/interrupt.h>
  56. #include <linux/major.h>
  57. #include <linux/errno.h>
  58. #include <linux/genhd.h>
  59. #include <linux/blkpg.h>
  60. #include <linux/slab.h>
  61. #include <linux/init.h>
  62. #include <linux/pci.h>
  63. #include <linux/delay.h>
  64. #include <linux/ide.h>
  65. #include <linux/completion.h>
  66. #include <linux/reboot.h>
  67. #include <linux/cdrom.h>
  68. #include <linux/seq_file.h>
  69. #include <linux/device.h>
  70. #include <linux/bitops.h>
  71. #include <asm/byteorder.h>
  72. #include <asm/irq.h>
  73. #include <asm/uaccess.h>
  74. #include <asm/io.h>
  75. /* default maximum number of failures */
  76. #define IDE_DEFAULT_MAX_FAILURES 1
  77. static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
  78. IDE2_MAJOR, IDE3_MAJOR,
  79. IDE4_MAJOR, IDE5_MAJOR,
  80. IDE6_MAJOR, IDE7_MAJOR,
  81. IDE8_MAJOR, IDE9_MAJOR };
  82. static int idebus_parameter; /* holds the "idebus=" parameter */
  83. static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */
  84. DEFINE_MUTEX(ide_cfg_mtx);
  85. __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
  86. #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
  87. static int ide_scan_direction; /* THIS was formerly 2.2.x pci=reverse */
  88. #endif
  89. int noautodma = 0;
  90. #ifdef CONFIG_BLK_DEV_IDEACPI
  91. int ide_noacpi = 0;
  92. int ide_noacpitfs = 1;
  93. int ide_noacpionboot = 1;
  94. #endif
  95. /*
  96. * This is declared extern in ide.h, for access by other IDE modules:
  97. */
  98. ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
  99. EXPORT_SYMBOL(ide_hwifs);
  100. /*
  101. * Do not even *think* about calling this!
  102. */
  103. static void init_hwif_data(ide_hwif_t *hwif, unsigned int index)
  104. {
  105. unsigned int unit;
  106. /* bulk initialize hwif & drive info with zeros */
  107. memset(hwif, 0, sizeof(ide_hwif_t));
  108. /* fill in any non-zero initial values */
  109. hwif->index = index;
  110. hwif->major = ide_hwif_to_major[index];
  111. hwif->name[0] = 'i';
  112. hwif->name[1] = 'd';
  113. hwif->name[2] = 'e';
  114. hwif->name[3] = '0' + index;
  115. hwif->bus_state = BUSSTATE_ON;
  116. init_completion(&hwif->gendev_rel_comp);
  117. default_hwif_iops(hwif);
  118. default_hwif_transport(hwif);
  119. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  120. ide_drive_t *drive = &hwif->drives[unit];
  121. drive->media = ide_disk;
  122. drive->select.all = (unit<<4)|0xa0;
  123. drive->hwif = hwif;
  124. drive->ctl = 0x08;
  125. drive->ready_stat = READY_STAT;
  126. drive->bad_wstat = BAD_W_STAT;
  127. drive->special.b.recalibrate = 1;
  128. drive->special.b.set_geometry = 1;
  129. drive->name[0] = 'h';
  130. drive->name[1] = 'd';
  131. drive->name[2] = 'a' + (index * MAX_DRIVES) + unit;
  132. drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
  133. drive->using_dma = 0;
  134. drive->vdma = 0;
  135. INIT_LIST_HEAD(&drive->list);
  136. init_completion(&drive->gendev_rel_comp);
  137. }
  138. }
  139. static void init_hwif_default(ide_hwif_t *hwif, unsigned int index)
  140. {
  141. hw_regs_t hw;
  142. memset(&hw, 0, sizeof(hw_regs_t));
  143. ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
  144. memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
  145. hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
  146. #ifdef CONFIG_BLK_DEV_HD
  147. if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)
  148. hwif->noprobe = 1; /* may be overridden by ide_setup() */
  149. #endif
  150. }
  151. extern void ide_arm_init(void);
  152. /*
  153. * init_ide_data() sets reasonable default values into all fields
  154. * of all instances of the hwifs and drives, but only on the first call.
  155. * Subsequent calls have no effect (they don't wipe out anything).
  156. *
  157. * This routine is normally called at driver initialization time,
  158. * but may also be called MUCH earlier during kernel "command-line"
  159. * parameter processing. As such, we cannot depend on any other parts
  160. * of the kernel (such as memory allocation) to be functioning yet.
  161. *
  162. * This is too bad, as otherwise we could dynamically allocate the
  163. * ide_drive_t structs as needed, rather than always consuming memory
  164. * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
  165. *
  166. * FIXME: We should stuff the setup data into __init and copy the
  167. * relevant hwifs/allocate them properly during boot.
  168. */
  169. #define MAGIC_COOKIE 0x12345678
  170. static void __init init_ide_data (void)
  171. {
  172. ide_hwif_t *hwif;
  173. unsigned int index;
  174. static unsigned long magic_cookie = MAGIC_COOKIE;
  175. if (magic_cookie != MAGIC_COOKIE)
  176. return; /* already initialized */
  177. magic_cookie = 0;
  178. /* Initialise all interface structures */
  179. for (index = 0; index < MAX_HWIFS; ++index) {
  180. hwif = &ide_hwifs[index];
  181. init_hwif_data(hwif, index);
  182. init_hwif_default(hwif, index);
  183. #if !defined(CONFIG_PPC32) || !defined(CONFIG_PCI)
  184. hwif->irq =
  185. ide_init_default_irq(hwif->io_ports[IDE_DATA_OFFSET]);
  186. #endif
  187. }
  188. #ifdef CONFIG_IDE_ARM
  189. ide_arm_init();
  190. #endif
  191. }
  192. /**
  193. * ide_system_bus_speed - guess bus speed
  194. *
  195. * ide_system_bus_speed() returns what we think is the system VESA/PCI
  196. * bus speed (in MHz). This is used for calculating interface PIO timings.
  197. * The default is 40 for known PCI systems, 50 otherwise.
  198. * The "idebus=xx" parameter can be used to override this value.
  199. * The actual value to be used is computed/displayed the first time
  200. * through. Drivers should only use this as a last resort.
  201. *
  202. * Returns a guessed speed in MHz.
  203. */
  204. static int ide_system_bus_speed(void)
  205. {
  206. #ifdef CONFIG_PCI
  207. static struct pci_device_id pci_default[] = {
  208. { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) },
  209. { }
  210. };
  211. #else
  212. #define pci_default 0
  213. #endif /* CONFIG_PCI */
  214. if (!system_bus_speed) {
  215. if (idebus_parameter) {
  216. /* user supplied value */
  217. system_bus_speed = idebus_parameter;
  218. } else if (pci_dev_present(pci_default)) {
  219. /* safe default value for PCI */
  220. system_bus_speed = 33;
  221. } else {
  222. /* safe default value for VESA and PCI */
  223. system_bus_speed = 50;
  224. }
  225. printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
  226. "for PIO modes%s\n", system_bus_speed,
  227. idebus_parameter ? "" : "; override with idebus=xx");
  228. }
  229. return system_bus_speed;
  230. }
  231. ide_hwif_t * ide_find_port(unsigned long base)
  232. {
  233. ide_hwif_t *hwif;
  234. int i;
  235. for (i = 0; i < MAX_HWIFS; i++) {
  236. hwif = &ide_hwifs[i];
  237. if (hwif->io_ports[IDE_DATA_OFFSET] == base)
  238. goto found;
  239. }
  240. for (i = 0; i < MAX_HWIFS; i++) {
  241. hwif = &ide_hwifs[i];
  242. if (hwif->io_ports[IDE_DATA_OFFSET] == 0)
  243. goto found;
  244. }
  245. hwif = NULL;
  246. found:
  247. return hwif;
  248. }
  249. EXPORT_SYMBOL_GPL(ide_find_port);
  250. static struct resource* hwif_request_region(ide_hwif_t *hwif,
  251. unsigned long addr, int num)
  252. {
  253. struct resource *res = request_region(addr, num, hwif->name);
  254. if (!res)
  255. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
  256. hwif->name, addr, addr+num-1);
  257. return res;
  258. }
  259. /**
  260. * ide_hwif_request_regions - request resources for IDE
  261. * @hwif: interface to use
  262. *
  263. * Requests all the needed resources for an interface.
  264. * Right now core IDE code does this work which is deeply wrong.
  265. * MMIO leaves it to the controller driver,
  266. * PIO will migrate this way over time.
  267. */
  268. int ide_hwif_request_regions(ide_hwif_t *hwif)
  269. {
  270. unsigned long addr;
  271. unsigned int i;
  272. if (hwif->mmio)
  273. return 0;
  274. addr = hwif->io_ports[IDE_CONTROL_OFFSET];
  275. if (addr && !hwif_request_region(hwif, addr, 1))
  276. goto control_region_busy;
  277. hwif->straight8 = 0;
  278. addr = hwif->io_ports[IDE_DATA_OFFSET];
  279. if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) {
  280. if (!hwif_request_region(hwif, addr, 8))
  281. goto data_region_busy;
  282. hwif->straight8 = 1;
  283. return 0;
  284. }
  285. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
  286. addr = hwif->io_ports[i];
  287. if (!hwif_request_region(hwif, addr, 1)) {
  288. while (--i)
  289. release_region(addr, 1);
  290. goto data_region_busy;
  291. }
  292. }
  293. return 0;
  294. data_region_busy:
  295. addr = hwif->io_ports[IDE_CONTROL_OFFSET];
  296. if (addr)
  297. release_region(addr, 1);
  298. control_region_busy:
  299. /* If any errors are return, we drop the hwif interface. */
  300. return -EBUSY;
  301. }
  302. /**
  303. * ide_hwif_release_regions - free IDE resources
  304. *
  305. * Note that we only release the standard ports,
  306. * and do not even try to handle any extra ports
  307. * allocated for weird IDE interface chipsets.
  308. *
  309. * Note also that we don't yet handle mmio resources here. More
  310. * importantly our caller should be doing this so we need to
  311. * restructure this as a helper function for drivers.
  312. */
  313. void ide_hwif_release_regions(ide_hwif_t *hwif)
  314. {
  315. u32 i = 0;
  316. if (hwif->mmio)
  317. return;
  318. if (hwif->io_ports[IDE_CONTROL_OFFSET])
  319. release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
  320. if (hwif->straight8) {
  321. release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
  322. return;
  323. }
  324. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
  325. if (hwif->io_ports[i])
  326. release_region(hwif->io_ports[i], 1);
  327. }
  328. /**
  329. * ide_hwif_restore - restore hwif to template
  330. * @hwif: hwif to update
  331. * @tmp_hwif: template
  332. *
  333. * Restore hwif to a previous state by copying most settings
  334. * from the template.
  335. */
  336. static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
  337. {
  338. hwif->hwgroup = tmp_hwif->hwgroup;
  339. hwif->gendev.parent = tmp_hwif->gendev.parent;
  340. hwif->proc = tmp_hwif->proc;
  341. hwif->major = tmp_hwif->major;
  342. hwif->straight8 = tmp_hwif->straight8;
  343. hwif->bus_state = tmp_hwif->bus_state;
  344. hwif->host_flags = tmp_hwif->host_flags;
  345. hwif->pio_mask = tmp_hwif->pio_mask;
  346. hwif->ultra_mask = tmp_hwif->ultra_mask;
  347. hwif->mwdma_mask = tmp_hwif->mwdma_mask;
  348. hwif->swdma_mask = tmp_hwif->swdma_mask;
  349. hwif->cbl = tmp_hwif->cbl;
  350. hwif->chipset = tmp_hwif->chipset;
  351. hwif->hold = tmp_hwif->hold;
  352. #ifdef CONFIG_BLK_DEV_IDEPCI
  353. hwif->pci_dev = tmp_hwif->pci_dev;
  354. hwif->cds = tmp_hwif->cds;
  355. #endif
  356. hwif->fixup = tmp_hwif->fixup;
  357. hwif->set_pio_mode = tmp_hwif->set_pio_mode;
  358. hwif->set_dma_mode = tmp_hwif->set_dma_mode;
  359. hwif->mdma_filter = tmp_hwif->mdma_filter;
  360. hwif->udma_filter = tmp_hwif->udma_filter;
  361. hwif->selectproc = tmp_hwif->selectproc;
  362. hwif->reset_poll = tmp_hwif->reset_poll;
  363. hwif->pre_reset = tmp_hwif->pre_reset;
  364. hwif->resetproc = tmp_hwif->resetproc;
  365. hwif->maskproc = tmp_hwif->maskproc;
  366. hwif->quirkproc = tmp_hwif->quirkproc;
  367. hwif->busproc = tmp_hwif->busproc;
  368. hwif->ata_input_data = tmp_hwif->ata_input_data;
  369. hwif->ata_output_data = tmp_hwif->ata_output_data;
  370. hwif->atapi_input_bytes = tmp_hwif->atapi_input_bytes;
  371. hwif->atapi_output_bytes = tmp_hwif->atapi_output_bytes;
  372. hwif->dma_setup = tmp_hwif->dma_setup;
  373. hwif->dma_exec_cmd = tmp_hwif->dma_exec_cmd;
  374. hwif->dma_start = tmp_hwif->dma_start;
  375. hwif->ide_dma_end = tmp_hwif->ide_dma_end;
  376. hwif->ide_dma_on = tmp_hwif->ide_dma_on;
  377. hwif->dma_off_quietly = tmp_hwif->dma_off_quietly;
  378. hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq;
  379. hwif->ide_dma_clear_irq = tmp_hwif->ide_dma_clear_irq;
  380. hwif->dma_host_on = tmp_hwif->dma_host_on;
  381. hwif->dma_host_off = tmp_hwif->dma_host_off;
  382. hwif->dma_lost_irq = tmp_hwif->dma_lost_irq;
  383. hwif->dma_timeout = tmp_hwif->dma_timeout;
  384. hwif->OUTB = tmp_hwif->OUTB;
  385. hwif->OUTBSYNC = tmp_hwif->OUTBSYNC;
  386. hwif->OUTW = tmp_hwif->OUTW;
  387. hwif->OUTSW = tmp_hwif->OUTSW;
  388. hwif->OUTSL = tmp_hwif->OUTSL;
  389. hwif->INB = tmp_hwif->INB;
  390. hwif->INW = tmp_hwif->INW;
  391. hwif->INSW = tmp_hwif->INSW;
  392. hwif->INSL = tmp_hwif->INSL;
  393. hwif->sg_max_nents = tmp_hwif->sg_max_nents;
  394. hwif->mmio = tmp_hwif->mmio;
  395. hwif->rqsize = tmp_hwif->rqsize;
  396. #ifndef CONFIG_BLK_DEV_IDECS
  397. hwif->irq = tmp_hwif->irq;
  398. #endif
  399. hwif->dma_base = tmp_hwif->dma_base;
  400. hwif->dma_command = tmp_hwif->dma_command;
  401. hwif->dma_vendor1 = tmp_hwif->dma_vendor1;
  402. hwif->dma_status = tmp_hwif->dma_status;
  403. hwif->dma_vendor3 = tmp_hwif->dma_vendor3;
  404. hwif->dma_prdtable = tmp_hwif->dma_prdtable;
  405. hwif->config_data = tmp_hwif->config_data;
  406. hwif->select_data = tmp_hwif->select_data;
  407. hwif->extra_base = tmp_hwif->extra_base;
  408. hwif->extra_ports = tmp_hwif->extra_ports;
  409. hwif->hwif_data = tmp_hwif->hwif_data;
  410. }
  411. /**
  412. * ide_unregister - free an IDE interface
  413. * @index: index of interface (will change soon to a pointer)
  414. *
  415. * Perform the final unregister of an IDE interface. At the moment
  416. * we don't refcount interfaces so this will also get split up.
  417. *
  418. * Locking:
  419. * The caller must not hold the IDE locks
  420. * The drive present/vanishing is not yet properly locked
  421. * Take care with the callbacks. These have been split to avoid
  422. * deadlocking the IDE layer. The shutdown callback is called
  423. * before we take the lock and free resources. It is up to the
  424. * caller to be sure there is no pending I/O here, and that
  425. * the interface will not be reopened (present/vanishing locking
  426. * isn't yet done BTW). After we commit to the final kill we
  427. * call the cleanup callback with the ide locks held.
  428. *
  429. * Unregister restores the hwif structures to the default state.
  430. * This is raving bonkers.
  431. */
  432. void ide_unregister(unsigned int index)
  433. {
  434. ide_drive_t *drive;
  435. ide_hwif_t *hwif, *g;
  436. static ide_hwif_t tmp_hwif; /* protected by ide_cfg_mtx */
  437. ide_hwgroup_t *hwgroup;
  438. int irq_count = 0, unit;
  439. BUG_ON(index >= MAX_HWIFS);
  440. BUG_ON(in_interrupt());
  441. BUG_ON(irqs_disabled());
  442. mutex_lock(&ide_cfg_mtx);
  443. spin_lock_irq(&ide_lock);
  444. hwif = &ide_hwifs[index];
  445. if (!hwif->present)
  446. goto abort;
  447. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  448. drive = &hwif->drives[unit];
  449. if (!drive->present)
  450. continue;
  451. spin_unlock_irq(&ide_lock);
  452. device_unregister(&drive->gendev);
  453. wait_for_completion(&drive->gendev_rel_comp);
  454. spin_lock_irq(&ide_lock);
  455. }
  456. hwif->present = 0;
  457. spin_unlock_irq(&ide_lock);
  458. ide_proc_unregister_port(hwif);
  459. hwgroup = hwif->hwgroup;
  460. /*
  461. * free the irq if we were the only hwif using it
  462. */
  463. g = hwgroup->hwif;
  464. do {
  465. if (g->irq == hwif->irq)
  466. ++irq_count;
  467. g = g->next;
  468. } while (g != hwgroup->hwif);
  469. if (irq_count == 1)
  470. free_irq(hwif->irq, hwgroup);
  471. spin_lock_irq(&ide_lock);
  472. /*
  473. * Note that we only release the standard ports,
  474. * and do not even try to handle any extra ports
  475. * allocated for weird IDE interface chipsets.
  476. */
  477. ide_hwif_release_regions(hwif);
  478. /*
  479. * Remove us from the hwgroup, and free
  480. * the hwgroup if we were the only member
  481. */
  482. if (hwif->next == hwif) {
  483. BUG_ON(hwgroup->hwif != hwif);
  484. kfree(hwgroup);
  485. } else {
  486. /* There is another interface in hwgroup.
  487. * Unlink us, and set hwgroup->drive and ->hwif to
  488. * something sane.
  489. */
  490. g = hwgroup->hwif;
  491. while (g->next != hwif)
  492. g = g->next;
  493. g->next = hwif->next;
  494. if (hwgroup->hwif == hwif) {
  495. /* Chose a random hwif for hwgroup->hwif.
  496. * It's guaranteed that there are no drives
  497. * left in the hwgroup.
  498. */
  499. BUG_ON(hwgroup->drive != NULL);
  500. hwgroup->hwif = g;
  501. }
  502. BUG_ON(hwgroup->hwif == hwif);
  503. }
  504. /* More messed up locking ... */
  505. spin_unlock_irq(&ide_lock);
  506. device_unregister(&hwif->gendev);
  507. wait_for_completion(&hwif->gendev_rel_comp);
  508. /*
  509. * Remove us from the kernel's knowledge
  510. */
  511. blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
  512. kfree(hwif->sg_table);
  513. unregister_blkdev(hwif->major, hwif->name);
  514. spin_lock_irq(&ide_lock);
  515. if (hwif->dma_base) {
  516. (void) ide_release_dma(hwif);
  517. hwif->dma_base = 0;
  518. hwif->dma_command = 0;
  519. hwif->dma_vendor1 = 0;
  520. hwif->dma_status = 0;
  521. hwif->dma_vendor3 = 0;
  522. hwif->dma_prdtable = 0;
  523. hwif->extra_base = 0;
  524. hwif->extra_ports = 0;
  525. }
  526. /* copy original settings */
  527. tmp_hwif = *hwif;
  528. /* restore hwif data to pristine status */
  529. init_hwif_data(hwif, index);
  530. init_hwif_default(hwif, index);
  531. ide_hwif_restore(hwif, &tmp_hwif);
  532. abort:
  533. spin_unlock_irq(&ide_lock);
  534. mutex_unlock(&ide_cfg_mtx);
  535. }
  536. EXPORT_SYMBOL(ide_unregister);
  537. /**
  538. * ide_setup_ports - set up IDE interface ports
  539. * @hw: register descriptions
  540. * @base: base register
  541. * @offsets: table of register offsets
  542. * @ctrl: control register
  543. * @ack_irq: IRQ ack
  544. * @irq: interrupt lie
  545. *
  546. * Setup hw_regs_t structure described by parameters. You
  547. * may set up the hw structure yourself OR use this routine to
  548. * do it for you. This is basically a helper
  549. *
  550. */
  551. void ide_setup_ports ( hw_regs_t *hw,
  552. unsigned long base, int *offsets,
  553. unsigned long ctrl, unsigned long intr,
  554. ide_ack_intr_t *ack_intr,
  555. /*
  556. * ide_io_ops_t *iops,
  557. */
  558. int irq)
  559. {
  560. int i;
  561. memset(hw, 0, sizeof(hw_regs_t));
  562. for (i = 0; i < IDE_NR_PORTS; i++) {
  563. if (offsets[i] == -1) {
  564. switch(i) {
  565. case IDE_CONTROL_OFFSET:
  566. hw->io_ports[i] = ctrl;
  567. break;
  568. #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
  569. case IDE_IRQ_OFFSET:
  570. hw->io_ports[i] = intr;
  571. break;
  572. #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
  573. default:
  574. hw->io_ports[i] = 0;
  575. break;
  576. }
  577. } else {
  578. hw->io_ports[i] = base + offsets[i];
  579. }
  580. }
  581. hw->irq = irq;
  582. hw->ack_intr = ack_intr;
  583. /*
  584. * hw->iops = iops;
  585. */
  586. }
  587. /**
  588. * ide_register_hw - register IDE interface
  589. * @hw: hardware registers
  590. * @fixup: fixup function
  591. * @initializing: set while initializing built-in drivers
  592. * @hwifp: pointer to returned hwif
  593. *
  594. * Register an IDE interface, specifying exactly the registers etc.
  595. * Set init=1 iff calling before probes have taken place.
  596. *
  597. * Returns -1 on error.
  598. */
  599. int ide_register_hw(hw_regs_t *hw, void (*fixup)(ide_hwif_t *),
  600. int initializing, ide_hwif_t **hwifp)
  601. {
  602. int index, retry = 1;
  603. ide_hwif_t *hwif;
  604. do {
  605. for (index = 0; index < MAX_HWIFS; ++index) {
  606. hwif = &ide_hwifs[index];
  607. if (hwif->io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
  608. goto found;
  609. }
  610. for (index = 0; index < MAX_HWIFS; ++index) {
  611. hwif = &ide_hwifs[index];
  612. if (hwif->hold)
  613. continue;
  614. if ((!hwif->present && !hwif->mate && !initializing) ||
  615. (!hwif->io_ports[IDE_DATA_OFFSET] && initializing))
  616. goto found;
  617. }
  618. for (index = 0; index < MAX_HWIFS; index++)
  619. ide_unregister(index);
  620. } while (retry--);
  621. return -1;
  622. found:
  623. if (hwif->present)
  624. ide_unregister(index);
  625. else if (!hwif->hold) {
  626. init_hwif_data(hwif, index);
  627. init_hwif_default(hwif, index);
  628. }
  629. if (hwif->present)
  630. return -1;
  631. memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
  632. hwif->irq = hw->irq;
  633. hwif->noprobe = 0;
  634. hwif->fixup = fixup;
  635. hwif->chipset = hw->chipset;
  636. hwif->gendev.parent = hw->dev;
  637. hwif->ack_intr = hw->ack_intr;
  638. if (initializing == 0) {
  639. u8 idx[4] = { index, 0xff, 0xff, 0xff };
  640. ide_device_add(idx);
  641. }
  642. if (hwifp)
  643. *hwifp = hwif;
  644. return (initializing || hwif->present) ? index : -1;
  645. }
  646. EXPORT_SYMBOL(ide_register_hw);
  647. /*
  648. * Locks for IDE setting functionality
  649. */
  650. DEFINE_MUTEX(ide_setting_mtx);
  651. EXPORT_SYMBOL_GPL(ide_setting_mtx);
  652. /**
  653. * ide_spin_wait_hwgroup - wait for group
  654. * @drive: drive in the group
  655. *
  656. * Wait for an IDE device group to go non busy and then return
  657. * holding the ide_lock which guards the hwgroup->busy status
  658. * and right to use it.
  659. */
  660. int ide_spin_wait_hwgroup (ide_drive_t *drive)
  661. {
  662. ide_hwgroup_t *hwgroup = HWGROUP(drive);
  663. unsigned long timeout = jiffies + (3 * HZ);
  664. spin_lock_irq(&ide_lock);
  665. while (hwgroup->busy) {
  666. unsigned long lflags;
  667. spin_unlock_irq(&ide_lock);
  668. local_irq_set(lflags);
  669. if (time_after(jiffies, timeout)) {
  670. local_irq_restore(lflags);
  671. printk(KERN_ERR "%s: channel busy\n", drive->name);
  672. return -EBUSY;
  673. }
  674. local_irq_restore(lflags);
  675. spin_lock_irq(&ide_lock);
  676. }
  677. return 0;
  678. }
  679. EXPORT_SYMBOL(ide_spin_wait_hwgroup);
  680. int set_io_32bit(ide_drive_t *drive, int arg)
  681. {
  682. if (drive->no_io_32bit)
  683. return -EPERM;
  684. if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
  685. return -EINVAL;
  686. if (ide_spin_wait_hwgroup(drive))
  687. return -EBUSY;
  688. drive->io_32bit = arg;
  689. #ifdef CONFIG_BLK_DEV_DTC2278
  690. if (HWIF(drive)->chipset == ide_dtc2278)
  691. HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
  692. #endif /* CONFIG_BLK_DEV_DTC2278 */
  693. spin_unlock_irq(&ide_lock);
  694. return 0;
  695. }
  696. static int set_ksettings(ide_drive_t *drive, int arg)
  697. {
  698. if (arg < 0 || arg > 1)
  699. return -EINVAL;
  700. if (ide_spin_wait_hwgroup(drive))
  701. return -EBUSY;
  702. drive->keep_settings = arg;
  703. spin_unlock_irq(&ide_lock);
  704. return 0;
  705. }
  706. int set_using_dma(ide_drive_t *drive, int arg)
  707. {
  708. #ifdef CONFIG_BLK_DEV_IDEDMA
  709. ide_hwif_t *hwif = drive->hwif;
  710. int err = -EPERM;
  711. if (arg < 0 || arg > 1)
  712. return -EINVAL;
  713. if (!drive->id || !(drive->id->capability & 1))
  714. goto out;
  715. if (hwif->ide_dma_on == NULL)
  716. goto out;
  717. err = -EBUSY;
  718. if (ide_spin_wait_hwgroup(drive))
  719. goto out;
  720. /*
  721. * set ->busy flag, unlock and let it ride
  722. */
  723. hwif->hwgroup->busy = 1;
  724. spin_unlock_irq(&ide_lock);
  725. err = 0;
  726. if (arg) {
  727. if (ide_set_dma(drive))
  728. err = -EIO;
  729. } else
  730. ide_dma_off(drive);
  731. /*
  732. * lock, clear ->busy flag and unlock before leaving
  733. */
  734. spin_lock_irq(&ide_lock);
  735. hwif->hwgroup->busy = 0;
  736. spin_unlock_irq(&ide_lock);
  737. out:
  738. return err;
  739. #else
  740. if (arg < 0 || arg > 1)
  741. return -EINVAL;
  742. return -EPERM;
  743. #endif
  744. }
  745. int set_pio_mode(ide_drive_t *drive, int arg)
  746. {
  747. struct request rq;
  748. if (arg < 0 || arg > 255)
  749. return -EINVAL;
  750. if (drive->hwif->set_pio_mode == NULL)
  751. return -ENOSYS;
  752. if (drive->special.b.set_tune)
  753. return -EBUSY;
  754. ide_init_drive_cmd(&rq);
  755. drive->tune_req = (u8) arg;
  756. drive->special.b.set_tune = 1;
  757. (void) ide_do_drive_cmd(drive, &rq, ide_wait);
  758. return 0;
  759. }
  760. static int set_unmaskirq(ide_drive_t *drive, int arg)
  761. {
  762. if (drive->no_unmask)
  763. return -EPERM;
  764. if (arg < 0 || arg > 1)
  765. return -EINVAL;
  766. if (ide_spin_wait_hwgroup(drive))
  767. return -EBUSY;
  768. drive->unmask = arg;
  769. spin_unlock_irq(&ide_lock);
  770. return 0;
  771. }
  772. /**
  773. * system_bus_clock - clock guess
  774. *
  775. * External version of the bus clock guess used by very old IDE drivers
  776. * for things like VLB timings. Should not be used.
  777. */
  778. int system_bus_clock (void)
  779. {
  780. return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
  781. }
  782. EXPORT_SYMBOL(system_bus_clock);
  783. static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
  784. {
  785. ide_drive_t *drive = dev->driver_data;
  786. ide_hwif_t *hwif = HWIF(drive);
  787. struct request rq;
  788. struct request_pm_state rqpm;
  789. ide_task_t args;
  790. int ret;
  791. /* Call ACPI _GTM only once */
  792. if (!(drive->dn % 2))
  793. ide_acpi_get_timing(hwif);
  794. memset(&rq, 0, sizeof(rq));
  795. memset(&rqpm, 0, sizeof(rqpm));
  796. memset(&args, 0, sizeof(args));
  797. rq.cmd_type = REQ_TYPE_PM_SUSPEND;
  798. rq.special = &args;
  799. rq.data = &rqpm;
  800. rqpm.pm_step = ide_pm_state_start_suspend;
  801. if (mesg.event == PM_EVENT_PRETHAW)
  802. mesg.event = PM_EVENT_FREEZE;
  803. rqpm.pm_state = mesg.event;
  804. ret = ide_do_drive_cmd(drive, &rq, ide_wait);
  805. /* only call ACPI _PS3 after both drivers are suspended */
  806. if (!ret && (((drive->dn % 2) && hwif->drives[0].present
  807. && hwif->drives[1].present)
  808. || !hwif->drives[0].present
  809. || !hwif->drives[1].present))
  810. ide_acpi_set_state(hwif, 0);
  811. return ret;
  812. }
  813. static int generic_ide_resume(struct device *dev)
  814. {
  815. ide_drive_t *drive = dev->driver_data;
  816. ide_hwif_t *hwif = HWIF(drive);
  817. struct request rq;
  818. struct request_pm_state rqpm;
  819. ide_task_t args;
  820. int err;
  821. /* Call ACPI _STM only once */
  822. if (!(drive->dn % 2)) {
  823. ide_acpi_set_state(hwif, 1);
  824. ide_acpi_push_timing(hwif);
  825. }
  826. ide_acpi_exec_tfs(drive);
  827. memset(&rq, 0, sizeof(rq));
  828. memset(&rqpm, 0, sizeof(rqpm));
  829. memset(&args, 0, sizeof(args));
  830. rq.cmd_type = REQ_TYPE_PM_RESUME;
  831. rq.special = &args;
  832. rq.data = &rqpm;
  833. rqpm.pm_step = ide_pm_state_start_resume;
  834. rqpm.pm_state = PM_EVENT_ON;
  835. err = ide_do_drive_cmd(drive, &rq, ide_head_wait);
  836. if (err == 0 && dev->driver) {
  837. ide_driver_t *drv = to_ide_driver(dev->driver);
  838. if (drv->resume)
  839. drv->resume(drive);
  840. }
  841. return err;
  842. }
  843. int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
  844. unsigned int cmd, unsigned long arg)
  845. {
  846. unsigned long flags;
  847. ide_driver_t *drv;
  848. void __user *p = (void __user *)arg;
  849. int err = 0, (*setfunc)(ide_drive_t *, int);
  850. u8 *val;
  851. switch (cmd) {
  852. case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val;
  853. case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
  854. case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val;
  855. case HDIO_GET_DMA: val = &drive->using_dma; goto read_val;
  856. case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val;
  857. case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val;
  858. case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val;
  859. case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val;
  860. case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val;
  861. }
  862. switch (cmd) {
  863. case HDIO_OBSOLETE_IDENTITY:
  864. case HDIO_GET_IDENTITY:
  865. if (bdev != bdev->bd_contains)
  866. return -EINVAL;
  867. if (drive->id_read == 0)
  868. return -ENOMSG;
  869. if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
  870. return -EFAULT;
  871. return 0;
  872. case HDIO_GET_NICE:
  873. return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
  874. drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
  875. drive->nice0 << IDE_NICE_0 |
  876. drive->nice1 << IDE_NICE_1 |
  877. drive->nice2 << IDE_NICE_2,
  878. (long __user *) arg);
  879. #ifdef CONFIG_IDE_TASK_IOCTL
  880. case HDIO_DRIVE_TASKFILE:
  881. if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
  882. return -EACCES;
  883. switch(drive->media) {
  884. case ide_disk:
  885. return ide_taskfile_ioctl(drive, cmd, arg);
  886. default:
  887. return -ENOMSG;
  888. }
  889. #endif /* CONFIG_IDE_TASK_IOCTL */
  890. case HDIO_DRIVE_CMD:
  891. if (!capable(CAP_SYS_RAWIO))
  892. return -EACCES;
  893. return ide_cmd_ioctl(drive, cmd, arg);
  894. case HDIO_DRIVE_TASK:
  895. if (!capable(CAP_SYS_RAWIO))
  896. return -EACCES;
  897. return ide_task_ioctl(drive, cmd, arg);
  898. case HDIO_SCAN_HWIF:
  899. {
  900. hw_regs_t hw;
  901. int args[3];
  902. if (!capable(CAP_SYS_RAWIO)) return -EACCES;
  903. if (copy_from_user(args, p, 3 * sizeof(int)))
  904. return -EFAULT;
  905. memset(&hw, 0, sizeof(hw));
  906. ide_init_hwif_ports(&hw, (unsigned long) args[0],
  907. (unsigned long) args[1], NULL);
  908. hw.irq = args[2];
  909. if (ide_register_hw(&hw, NULL, 0, NULL) == -1)
  910. return -EIO;
  911. return 0;
  912. }
  913. case HDIO_UNREGISTER_HWIF:
  914. if (!capable(CAP_SYS_RAWIO)) return -EACCES;
  915. /* (arg > MAX_HWIFS) checked in function */
  916. ide_unregister(arg);
  917. return 0;
  918. case HDIO_SET_NICE:
  919. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  920. if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
  921. return -EPERM;
  922. drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
  923. drv = *(ide_driver_t **)bdev->bd_disk->private_data;
  924. if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
  925. drive->dsc_overlap = 0;
  926. return -EPERM;
  927. }
  928. drive->nice1 = (arg >> IDE_NICE_1) & 1;
  929. return 0;
  930. case HDIO_DRIVE_RESET:
  931. {
  932. unsigned long flags;
  933. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  934. /*
  935. * Abort the current command on the
  936. * group if there is one, taking
  937. * care not to allow anything else
  938. * to be queued and to die on the
  939. * spot if we miss one somehow
  940. */
  941. spin_lock_irqsave(&ide_lock, flags);
  942. if (HWGROUP(drive)->resetting) {
  943. spin_unlock_irqrestore(&ide_lock, flags);
  944. return -EBUSY;
  945. }
  946. ide_abort(drive, "drive reset");
  947. BUG_ON(HWGROUP(drive)->handler);
  948. /* Ensure nothing gets queued after we
  949. drop the lock. Reset will clear the busy */
  950. HWGROUP(drive)->busy = 1;
  951. spin_unlock_irqrestore(&ide_lock, flags);
  952. (void) ide_do_reset(drive);
  953. return 0;
  954. }
  955. case HDIO_GET_BUSSTATE:
  956. if (!capable(CAP_SYS_ADMIN))
  957. return -EACCES;
  958. if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
  959. return -EFAULT;
  960. return 0;
  961. case HDIO_SET_BUSSTATE:
  962. if (!capable(CAP_SYS_ADMIN))
  963. return -EACCES;
  964. if (HWIF(drive)->busproc)
  965. return HWIF(drive)->busproc(drive, (int)arg);
  966. return -EOPNOTSUPP;
  967. default:
  968. return -EINVAL;
  969. }
  970. read_val:
  971. mutex_lock(&ide_setting_mtx);
  972. spin_lock_irqsave(&ide_lock, flags);
  973. err = *val;
  974. spin_unlock_irqrestore(&ide_lock, flags);
  975. mutex_unlock(&ide_setting_mtx);
  976. return err >= 0 ? put_user(err, (long __user *)arg) : err;
  977. set_val:
  978. if (bdev != bdev->bd_contains)
  979. err = -EINVAL;
  980. else {
  981. if (!capable(CAP_SYS_ADMIN))
  982. err = -EACCES;
  983. else {
  984. mutex_lock(&ide_setting_mtx);
  985. err = setfunc(drive, arg);
  986. mutex_unlock(&ide_setting_mtx);
  987. }
  988. }
  989. return err;
  990. }
  991. EXPORT_SYMBOL(generic_ide_ioctl);
  992. /*
  993. * stridx() returns the offset of c within s,
  994. * or -1 if c is '\0' or not found within s.
  995. */
  996. static int __init stridx (const char *s, char c)
  997. {
  998. char *i = strchr(s, c);
  999. return (i && c) ? i - s : -1;
  1000. }
  1001. /*
  1002. * match_parm() does parsing for ide_setup():
  1003. *
  1004. * 1. the first char of s must be '='.
  1005. * 2. if the remainder matches one of the supplied keywords,
  1006. * the index (1 based) of the keyword is negated and returned.
  1007. * 3. if the remainder is a series of no more than max_vals numbers
  1008. * separated by commas, the numbers are saved in vals[] and a
  1009. * count of how many were saved is returned. Base10 is assumed,
  1010. * and base16 is allowed when prefixed with "0x".
  1011. * 4. otherwise, zero is returned.
  1012. */
  1013. static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
  1014. {
  1015. static const char *decimal = "0123456789";
  1016. static const char *hex = "0123456789abcdef";
  1017. int i, n;
  1018. if (*s++ == '=') {
  1019. /*
  1020. * Try matching against the supplied keywords,
  1021. * and return -(index+1) if we match one
  1022. */
  1023. if (keywords != NULL) {
  1024. for (i = 0; *keywords != NULL; ++i) {
  1025. if (!strcmp(s, *keywords++))
  1026. return -(i+1);
  1027. }
  1028. }
  1029. /*
  1030. * Look for a series of no more than "max_vals"
  1031. * numeric values separated by commas, in base10,
  1032. * or base16 when prefixed with "0x".
  1033. * Return a count of how many were found.
  1034. */
  1035. for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
  1036. vals[n] = i;
  1037. while ((i = stridx(decimal, *++s)) >= 0)
  1038. vals[n] = (vals[n] * 10) + i;
  1039. if (*s == 'x' && !vals[n]) {
  1040. while ((i = stridx(hex, *++s)) >= 0)
  1041. vals[n] = (vals[n] * 0x10) + i;
  1042. }
  1043. if (++n == max_vals)
  1044. break;
  1045. if (*s == ',' || *s == ';')
  1046. ++s;
  1047. }
  1048. if (!*s)
  1049. return n;
  1050. }
  1051. return 0; /* zero = nothing matched */
  1052. }
  1053. #ifdef CONFIG_BLK_DEV_ALI14XX
  1054. extern int probe_ali14xx;
  1055. extern int ali14xx_init(void);
  1056. #endif
  1057. #ifdef CONFIG_BLK_DEV_UMC8672
  1058. extern int probe_umc8672;
  1059. extern int umc8672_init(void);
  1060. #endif
  1061. #ifdef CONFIG_BLK_DEV_DTC2278
  1062. extern int probe_dtc2278;
  1063. extern int dtc2278_init(void);
  1064. #endif
  1065. #ifdef CONFIG_BLK_DEV_HT6560B
  1066. extern int probe_ht6560b;
  1067. extern int ht6560b_init(void);
  1068. #endif
  1069. #ifdef CONFIG_BLK_DEV_QD65XX
  1070. extern int probe_qd65xx;
  1071. extern int qd65xx_init(void);
  1072. #endif
  1073. static int __initdata is_chipset_set[MAX_HWIFS];
  1074. /*
  1075. * ide_setup() gets called VERY EARLY during initialization,
  1076. * to handle kernel "command line" strings beginning with "hdx=" or "ide".
  1077. *
  1078. * Remember to update Documentation/ide.txt if you change something here.
  1079. */
  1080. static int __init ide_setup(char *s)
  1081. {
  1082. int i, vals[3];
  1083. ide_hwif_t *hwif;
  1084. ide_drive_t *drive;
  1085. unsigned int hw, unit;
  1086. const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
  1087. const char max_hwif = '0' + (MAX_HWIFS - 1);
  1088. if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
  1089. return 0; /* driver and not us */
  1090. if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
  1091. return 0;
  1092. printk(KERN_INFO "ide_setup: %s", s);
  1093. init_ide_data ();
  1094. #ifdef CONFIG_BLK_DEV_IDEDOUBLER
  1095. if (!strcmp(s, "ide=doubler")) {
  1096. extern int ide_doubler;
  1097. printk(" : Enabled support for IDE doublers\n");
  1098. ide_doubler = 1;
  1099. return 1;
  1100. }
  1101. #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
  1102. if (!strcmp(s, "ide=nodma")) {
  1103. printk(" : Prevented DMA\n");
  1104. noautodma = 1;
  1105. goto obsolete_option;
  1106. }
  1107. #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
  1108. if (!strcmp(s, "ide=reverse")) {
  1109. ide_scan_direction = 1;
  1110. printk(" : Enabled support for IDE inverse scan order.\n");
  1111. return 1;
  1112. }
  1113. #endif
  1114. #ifdef CONFIG_BLK_DEV_IDEACPI
  1115. if (!strcmp(s, "ide=noacpi")) {
  1116. //printk(" : Disable IDE ACPI support.\n");
  1117. ide_noacpi = 1;
  1118. return 1;
  1119. }
  1120. if (!strcmp(s, "ide=acpigtf")) {
  1121. //printk(" : Enable IDE ACPI _GTF support.\n");
  1122. ide_noacpitfs = 0;
  1123. return 1;
  1124. }
  1125. if (!strcmp(s, "ide=acpionboot")) {
  1126. //printk(" : Call IDE ACPI methods on boot.\n");
  1127. ide_noacpionboot = 0;
  1128. return 1;
  1129. }
  1130. #endif /* CONFIG_BLK_DEV_IDEACPI */
  1131. /*
  1132. * Look for drive options: "hdx="
  1133. */
  1134. if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
  1135. const char *hd_words[] = {
  1136. "none", "noprobe", "nowerr", "cdrom", "nodma",
  1137. "autotune", "noautotune", "minus8", "swapdata", "bswap",
  1138. "noflush", "remap", "remap63", "scsi", NULL };
  1139. unit = s[2] - 'a';
  1140. hw = unit / MAX_DRIVES;
  1141. unit = unit % MAX_DRIVES;
  1142. hwif = &ide_hwifs[hw];
  1143. drive = &hwif->drives[unit];
  1144. if (strncmp(s + 4, "ide-", 4) == 0) {
  1145. strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
  1146. goto done;
  1147. }
  1148. switch (match_parm(&s[3], hd_words, vals, 3)) {
  1149. case -1: /* "none" */
  1150. case -2: /* "noprobe" */
  1151. drive->noprobe = 1;
  1152. goto done;
  1153. case -3: /* "nowerr" */
  1154. drive->bad_wstat = BAD_R_STAT;
  1155. hwif->noprobe = 0;
  1156. goto done;
  1157. case -4: /* "cdrom" */
  1158. drive->present = 1;
  1159. drive->media = ide_cdrom;
  1160. /* an ATAPI device ignores DRDY */
  1161. drive->ready_stat = 0;
  1162. hwif->noprobe = 0;
  1163. goto done;
  1164. case -5: /* nodma */
  1165. drive->nodma = 1;
  1166. goto done;
  1167. case -6: /* "autotune" */
  1168. drive->autotune = IDE_TUNE_AUTO;
  1169. goto obsolete_option;
  1170. case -7: /* "noautotune" */
  1171. drive->autotune = IDE_TUNE_NOAUTO;
  1172. goto obsolete_option;
  1173. case -9: /* "swapdata" */
  1174. case -10: /* "bswap" */
  1175. drive->bswap = 1;
  1176. goto done;
  1177. case -11: /* noflush */
  1178. drive->noflush = 1;
  1179. goto done;
  1180. case -12: /* "remap" */
  1181. drive->remap_0_to_1 = 1;
  1182. goto done;
  1183. case -13: /* "remap63" */
  1184. drive->sect0 = 63;
  1185. goto done;
  1186. case -14: /* "scsi" */
  1187. drive->scsi = 1;
  1188. goto done;
  1189. case 3: /* cyl,head,sect */
  1190. drive->media = ide_disk;
  1191. drive->ready_stat = READY_STAT;
  1192. drive->cyl = drive->bios_cyl = vals[0];
  1193. drive->head = drive->bios_head = vals[1];
  1194. drive->sect = drive->bios_sect = vals[2];
  1195. drive->present = 1;
  1196. drive->forced_geom = 1;
  1197. hwif->noprobe = 0;
  1198. goto done;
  1199. default:
  1200. goto bad_option;
  1201. }
  1202. }
  1203. if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
  1204. goto bad_option;
  1205. /*
  1206. * Look for bus speed option: "idebus="
  1207. */
  1208. if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
  1209. if (match_parm(&s[6], NULL, vals, 1) != 1)
  1210. goto bad_option;
  1211. if (vals[0] >= 20 && vals[0] <= 66) {
  1212. idebus_parameter = vals[0];
  1213. } else
  1214. printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
  1215. goto done;
  1216. }
  1217. /*
  1218. * Look for interface options: "idex="
  1219. */
  1220. if (s[3] >= '0' && s[3] <= max_hwif) {
  1221. /*
  1222. * Be VERY CAREFUL changing this: note hardcoded indexes below
  1223. * (-8, -9, -10) are reserved to ease the hardcoding.
  1224. */
  1225. static const char *ide_words[] = {
  1226. "noprobe", "serialize", "minus3", "minus4",
  1227. "reset", "minus6", "ata66", "minus8", "minus9",
  1228. "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
  1229. "dtc2278", "umc8672", "ali14xx", NULL };
  1230. hw_regs_t hwregs;
  1231. hw = s[3] - '0';
  1232. hwif = &ide_hwifs[hw];
  1233. i = match_parm(&s[4], ide_words, vals, 3);
  1234. /*
  1235. * Cryptic check to ensure chipset not already set for hwif.
  1236. * Note: we can't depend on hwif->chipset here.
  1237. */
  1238. if ((i >= -18 && i <= -11) || (i > 0 && i <= 3)) {
  1239. /* chipset already specified */
  1240. if (is_chipset_set[hw])
  1241. goto bad_option;
  1242. if (i > -18 && i <= -11) {
  1243. /* these drivers are for "ide0=" only */
  1244. if (hw != 0)
  1245. goto bad_hwif;
  1246. /* chipset already specified for 2nd port */
  1247. if (is_chipset_set[hw+1])
  1248. goto bad_option;
  1249. }
  1250. is_chipset_set[hw] = 1;
  1251. printk("\n");
  1252. }
  1253. switch (i) {
  1254. #ifdef CONFIG_BLK_DEV_ALI14XX
  1255. case -17: /* "ali14xx" */
  1256. probe_ali14xx = 1;
  1257. goto done;
  1258. #endif
  1259. #ifdef CONFIG_BLK_DEV_UMC8672
  1260. case -16: /* "umc8672" */
  1261. probe_umc8672 = 1;
  1262. goto done;
  1263. #endif
  1264. #ifdef CONFIG_BLK_DEV_DTC2278
  1265. case -15: /* "dtc2278" */
  1266. probe_dtc2278 = 1;
  1267. goto done;
  1268. #endif
  1269. #ifdef CONFIG_BLK_DEV_CMD640
  1270. case -14: /* "cmd640_vlb" */
  1271. {
  1272. extern int cmd640_vlb; /* flag for cmd640.c */
  1273. cmd640_vlb = 1;
  1274. goto done;
  1275. }
  1276. #endif
  1277. #ifdef CONFIG_BLK_DEV_HT6560B
  1278. case -13: /* "ht6560b" */
  1279. probe_ht6560b = 1;
  1280. goto done;
  1281. #endif
  1282. #ifdef CONFIG_BLK_DEV_QD65XX
  1283. case -12: /* "qd65xx" */
  1284. probe_qd65xx = 1;
  1285. goto done;
  1286. #endif
  1287. #ifdef CONFIG_BLK_DEV_4DRIVES
  1288. case -11: /* "four" drives on one set of ports */
  1289. {
  1290. ide_hwif_t *mate = &ide_hwifs[hw^1];
  1291. mate->drives[0].select.all ^= 0x20;
  1292. mate->drives[1].select.all ^= 0x20;
  1293. hwif->chipset = mate->chipset = ide_4drives;
  1294. mate->irq = hwif->irq;
  1295. memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
  1296. hwif->mate = mate;
  1297. mate->mate = hwif;
  1298. hwif->serialized = mate->serialized = 1;
  1299. goto obsolete_option;
  1300. }
  1301. #endif /* CONFIG_BLK_DEV_4DRIVES */
  1302. case -10: /* minus10 */
  1303. case -9: /* minus9 */
  1304. case -8: /* minus8 */
  1305. case -6:
  1306. case -4:
  1307. case -3:
  1308. goto bad_option;
  1309. case -7: /* ata66 */
  1310. #ifdef CONFIG_BLK_DEV_IDEPCI
  1311. /*
  1312. * Use ATA_CBL_PATA40_SHORT so drive side
  1313. * cable detection is also overriden.
  1314. */
  1315. hwif->cbl = ATA_CBL_PATA40_SHORT;
  1316. goto obsolete_option;
  1317. #else
  1318. goto bad_hwif;
  1319. #endif
  1320. case -5: /* "reset" */
  1321. hwif->reset = 1;
  1322. goto obsolete_option;
  1323. case -2: /* "serialize" */
  1324. hwif->mate = &ide_hwifs[hw^1];
  1325. hwif->mate->mate = hwif;
  1326. hwif->serialized = hwif->mate->serialized = 1;
  1327. goto obsolete_option;
  1328. case -1: /* "noprobe" */
  1329. hwif->noprobe = 1;
  1330. goto done;
  1331. case 1: /* base */
  1332. vals[1] = vals[0] + 0x206; /* default ctl */
  1333. case 2: /* base,ctl */
  1334. vals[2] = 0; /* default irq = probe for it */
  1335. case 3: /* base,ctl,irq */
  1336. memset(&hwregs, 0, sizeof(hwregs));
  1337. ide_init_hwif_ports(&hwregs, vals[0], vals[1], &hwif->irq);
  1338. memcpy(hwif->io_ports, hwregs.io_ports, sizeof(hwif->io_ports));
  1339. hwif->irq = vals[2];
  1340. hwif->noprobe = 0;
  1341. hwif->chipset = ide_forced;
  1342. goto obsolete_option;
  1343. case 0: goto bad_option;
  1344. default:
  1345. printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
  1346. return 1;
  1347. }
  1348. }
  1349. bad_option:
  1350. printk(" -- BAD OPTION\n");
  1351. return 1;
  1352. obsolete_option:
  1353. printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
  1354. return 1;
  1355. bad_hwif:
  1356. printk("-- NOT SUPPORTED ON ide%d", hw);
  1357. done:
  1358. printk("\n");
  1359. return 1;
  1360. }
  1361. extern void __init pnpide_init(void);
  1362. extern void __exit pnpide_exit(void);
  1363. extern void __init h8300_ide_init(void);
  1364. /*
  1365. * probe_for_hwifs() finds/initializes "known" IDE interfaces
  1366. */
  1367. static void __init probe_for_hwifs (void)
  1368. {
  1369. #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
  1370. ide_scan_pcibus(ide_scan_direction);
  1371. #endif
  1372. #ifdef CONFIG_ETRAX_IDE
  1373. {
  1374. extern void init_e100_ide(void);
  1375. init_e100_ide();
  1376. }
  1377. #endif /* CONFIG_ETRAX_IDE */
  1378. #ifdef CONFIG_BLK_DEV_CMD640
  1379. {
  1380. extern void ide_probe_for_cmd640x(void);
  1381. ide_probe_for_cmd640x();
  1382. }
  1383. #endif /* CONFIG_BLK_DEV_CMD640 */
  1384. #ifdef CONFIG_BLK_DEV_IDE_PMAC
  1385. {
  1386. extern int pmac_ide_probe(void);
  1387. (void)pmac_ide_probe();
  1388. }
  1389. #endif /* CONFIG_BLK_DEV_IDE_PMAC */
  1390. #ifdef CONFIG_BLK_DEV_GAYLE
  1391. {
  1392. extern void gayle_init(void);
  1393. gayle_init();
  1394. }
  1395. #endif /* CONFIG_BLK_DEV_GAYLE */
  1396. #ifdef CONFIG_BLK_DEV_FALCON_IDE
  1397. {
  1398. extern void falconide_init(void);
  1399. falconide_init();
  1400. }
  1401. #endif /* CONFIG_BLK_DEV_FALCON_IDE */
  1402. #ifdef CONFIG_BLK_DEV_MAC_IDE
  1403. {
  1404. extern void macide_init(void);
  1405. macide_init();
  1406. }
  1407. #endif /* CONFIG_BLK_DEV_MAC_IDE */
  1408. #ifdef CONFIG_BLK_DEV_Q40IDE
  1409. {
  1410. extern void q40ide_init(void);
  1411. q40ide_init();
  1412. }
  1413. #endif /* CONFIG_BLK_DEV_Q40IDE */
  1414. #ifdef CONFIG_BLK_DEV_BUDDHA
  1415. {
  1416. extern void buddha_init(void);
  1417. buddha_init();
  1418. }
  1419. #endif /* CONFIG_BLK_DEV_BUDDHA */
  1420. #ifdef CONFIG_BLK_DEV_IDEPNP
  1421. pnpide_init();
  1422. #endif
  1423. #ifdef CONFIG_H8300
  1424. h8300_ide_init();
  1425. #endif
  1426. }
  1427. /*
  1428. * Probe module
  1429. */
  1430. EXPORT_SYMBOL(ide_lock);
  1431. static int ide_bus_match(struct device *dev, struct device_driver *drv)
  1432. {
  1433. return 1;
  1434. }
  1435. static char *media_string(ide_drive_t *drive)
  1436. {
  1437. switch (drive->media) {
  1438. case ide_disk:
  1439. return "disk";
  1440. case ide_cdrom:
  1441. return "cdrom";
  1442. case ide_tape:
  1443. return "tape";
  1444. case ide_floppy:
  1445. return "floppy";
  1446. case ide_optical:
  1447. return "optical";
  1448. default:
  1449. return "UNKNOWN";
  1450. }
  1451. }
  1452. static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
  1453. {
  1454. ide_drive_t *drive = to_ide_device(dev);
  1455. return sprintf(buf, "%s\n", media_string(drive));
  1456. }
  1457. static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
  1458. {
  1459. ide_drive_t *drive = to_ide_device(dev);
  1460. return sprintf(buf, "%s\n", drive->name);
  1461. }
  1462. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
  1463. {
  1464. ide_drive_t *drive = to_ide_device(dev);
  1465. return sprintf(buf, "ide:m-%s\n", media_string(drive));
  1466. }
  1467. static ssize_t model_show(struct device *dev, struct device_attribute *attr,
  1468. char *buf)
  1469. {
  1470. ide_drive_t *drive = to_ide_device(dev);
  1471. return sprintf(buf, "%s\n", drive->id->model);
  1472. }
  1473. static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
  1474. char *buf)
  1475. {
  1476. ide_drive_t *drive = to_ide_device(dev);
  1477. return sprintf(buf, "%s\n", drive->id->fw_rev);
  1478. }
  1479. static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
  1480. char *buf)
  1481. {
  1482. ide_drive_t *drive = to_ide_device(dev);
  1483. return sprintf(buf, "%s\n", drive->id->serial_no);
  1484. }
  1485. static struct device_attribute ide_dev_attrs[] = {
  1486. __ATTR_RO(media),
  1487. __ATTR_RO(drivename),
  1488. __ATTR_RO(modalias),
  1489. __ATTR_RO(model),
  1490. __ATTR_RO(firmware),
  1491. __ATTR(serial, 0400, serial_show, NULL),
  1492. __ATTR_NULL
  1493. };
  1494. static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
  1495. {
  1496. ide_drive_t *drive = to_ide_device(dev);
  1497. add_uevent_var(env, "MEDIA=%s", media_string(drive));
  1498. add_uevent_var(env, "DRIVENAME=%s", drive->name);
  1499. add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive));
  1500. return 0;
  1501. }
  1502. static int generic_ide_probe(struct device *dev)
  1503. {
  1504. ide_drive_t *drive = to_ide_device(dev);
  1505. ide_driver_t *drv = to_ide_driver(dev->driver);
  1506. return drv->probe ? drv->probe(drive) : -ENODEV;
  1507. }
  1508. static int generic_ide_remove(struct device *dev)
  1509. {
  1510. ide_drive_t *drive = to_ide_device(dev);
  1511. ide_driver_t *drv = to_ide_driver(dev->driver);
  1512. if (drv->remove)
  1513. drv->remove(drive);
  1514. return 0;
  1515. }
  1516. static void generic_ide_shutdown(struct device *dev)
  1517. {
  1518. ide_drive_t *drive = to_ide_device(dev);
  1519. ide_driver_t *drv = to_ide_driver(dev->driver);
  1520. if (dev->driver && drv->shutdown)
  1521. drv->shutdown(drive);
  1522. }
  1523. struct bus_type ide_bus_type = {
  1524. .name = "ide",
  1525. .match = ide_bus_match,
  1526. .uevent = ide_uevent,
  1527. .probe = generic_ide_probe,
  1528. .remove = generic_ide_remove,
  1529. .shutdown = generic_ide_shutdown,
  1530. .dev_attrs = ide_dev_attrs,
  1531. .suspend = generic_ide_suspend,
  1532. .resume = generic_ide_resume,
  1533. };
  1534. EXPORT_SYMBOL_GPL(ide_bus_type);
  1535. /*
  1536. * This is gets invoked once during initialization, to set *everything* up
  1537. */
  1538. static int __init ide_init(void)
  1539. {
  1540. int ret;
  1541. printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
  1542. system_bus_speed = ide_system_bus_speed();
  1543. ret = bus_register(&ide_bus_type);
  1544. if (ret < 0) {
  1545. printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
  1546. return ret;
  1547. }
  1548. init_ide_data();
  1549. proc_ide_create();
  1550. #ifdef CONFIG_BLK_DEV_ALI14XX
  1551. if (probe_ali14xx)
  1552. (void)ali14xx_init();
  1553. #endif
  1554. #ifdef CONFIG_BLK_DEV_UMC8672
  1555. if (probe_umc8672)
  1556. (void)umc8672_init();
  1557. #endif
  1558. #ifdef CONFIG_BLK_DEV_DTC2278
  1559. if (probe_dtc2278)
  1560. (void)dtc2278_init();
  1561. #endif
  1562. #ifdef CONFIG_BLK_DEV_HT6560B
  1563. if (probe_ht6560b)
  1564. (void)ht6560b_init();
  1565. #endif
  1566. #ifdef CONFIG_BLK_DEV_QD65XX
  1567. if (probe_qd65xx)
  1568. (void)qd65xx_init();
  1569. #endif
  1570. /* Probe for special PCI and other "known" interface chipsets. */
  1571. probe_for_hwifs();
  1572. return 0;
  1573. }
  1574. #ifdef MODULE
  1575. static char *options = NULL;
  1576. module_param(options, charp, 0);
  1577. MODULE_LICENSE("GPL");
  1578. static void __init parse_options (char *line)
  1579. {
  1580. char *next = line;
  1581. if (line == NULL || !*line)
  1582. return;
  1583. while ((line = next) != NULL) {
  1584. if ((next = strchr(line,' ')) != NULL)
  1585. *next++ = 0;
  1586. if (!ide_setup(line))
  1587. printk (KERN_INFO "Unknown option '%s'\n", line);
  1588. }
  1589. }
  1590. int __init init_module (void)
  1591. {
  1592. parse_options(options);
  1593. return ide_init();
  1594. }
  1595. void __exit cleanup_module (void)
  1596. {
  1597. int index;
  1598. for (index = 0; index < MAX_HWIFS; ++index)
  1599. ide_unregister(index);
  1600. #ifdef CONFIG_BLK_DEV_IDEPNP
  1601. pnpide_exit();
  1602. #endif
  1603. proc_ide_destroy();
  1604. bus_unregister(&ide_bus_type);
  1605. }
  1606. #else /* !MODULE */
  1607. __setup("", ide_setup);
  1608. module_init(ide_init);
  1609. #endif /* MODULE */