ide.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847
  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->set_pio_mode = tmp_hwif->set_pio_mode;
  357. hwif->set_dma_mode = tmp_hwif->set_dma_mode;
  358. hwif->mdma_filter = tmp_hwif->mdma_filter;
  359. hwif->udma_filter = tmp_hwif->udma_filter;
  360. hwif->selectproc = tmp_hwif->selectproc;
  361. hwif->reset_poll = tmp_hwif->reset_poll;
  362. hwif->pre_reset = tmp_hwif->pre_reset;
  363. hwif->resetproc = tmp_hwif->resetproc;
  364. hwif->maskproc = tmp_hwif->maskproc;
  365. hwif->quirkproc = tmp_hwif->quirkproc;
  366. hwif->busproc = tmp_hwif->busproc;
  367. hwif->ata_input_data = tmp_hwif->ata_input_data;
  368. hwif->ata_output_data = tmp_hwif->ata_output_data;
  369. hwif->atapi_input_bytes = tmp_hwif->atapi_input_bytes;
  370. hwif->atapi_output_bytes = tmp_hwif->atapi_output_bytes;
  371. hwif->dma_host_set = tmp_hwif->dma_host_set;
  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_test_irq = tmp_hwif->ide_dma_test_irq;
  377. hwif->ide_dma_clear_irq = tmp_hwif->ide_dma_clear_irq;
  378. hwif->dma_lost_irq = tmp_hwif->dma_lost_irq;
  379. hwif->dma_timeout = tmp_hwif->dma_timeout;
  380. hwif->OUTB = tmp_hwif->OUTB;
  381. hwif->OUTBSYNC = tmp_hwif->OUTBSYNC;
  382. hwif->OUTW = tmp_hwif->OUTW;
  383. hwif->OUTSW = tmp_hwif->OUTSW;
  384. hwif->OUTSL = tmp_hwif->OUTSL;
  385. hwif->INB = tmp_hwif->INB;
  386. hwif->INW = tmp_hwif->INW;
  387. hwif->INSW = tmp_hwif->INSW;
  388. hwif->INSL = tmp_hwif->INSL;
  389. hwif->sg_max_nents = tmp_hwif->sg_max_nents;
  390. hwif->mmio = tmp_hwif->mmio;
  391. hwif->rqsize = tmp_hwif->rqsize;
  392. #ifndef CONFIG_BLK_DEV_IDECS
  393. hwif->irq = tmp_hwif->irq;
  394. #endif
  395. hwif->dma_base = tmp_hwif->dma_base;
  396. hwif->dma_command = tmp_hwif->dma_command;
  397. hwif->dma_vendor1 = tmp_hwif->dma_vendor1;
  398. hwif->dma_status = tmp_hwif->dma_status;
  399. hwif->dma_vendor3 = tmp_hwif->dma_vendor3;
  400. hwif->dma_prdtable = tmp_hwif->dma_prdtable;
  401. hwif->config_data = tmp_hwif->config_data;
  402. hwif->select_data = tmp_hwif->select_data;
  403. hwif->extra_base = tmp_hwif->extra_base;
  404. hwif->extra_ports = tmp_hwif->extra_ports;
  405. hwif->hwif_data = tmp_hwif->hwif_data;
  406. }
  407. /**
  408. * ide_unregister - free an IDE interface
  409. * @index: index of interface (will change soon to a pointer)
  410. *
  411. * Perform the final unregister of an IDE interface. At the moment
  412. * we don't refcount interfaces so this will also get split up.
  413. *
  414. * Locking:
  415. * The caller must not hold the IDE locks
  416. * The drive present/vanishing is not yet properly locked
  417. * Take care with the callbacks. These have been split to avoid
  418. * deadlocking the IDE layer. The shutdown callback is called
  419. * before we take the lock and free resources. It is up to the
  420. * caller to be sure there is no pending I/O here, and that
  421. * the interface will not be reopened (present/vanishing locking
  422. * isn't yet done BTW). After we commit to the final kill we
  423. * call the cleanup callback with the ide locks held.
  424. *
  425. * Unregister restores the hwif structures to the default state.
  426. * This is raving bonkers.
  427. */
  428. void ide_unregister(unsigned int index)
  429. {
  430. ide_drive_t *drive;
  431. ide_hwif_t *hwif, *g;
  432. static ide_hwif_t tmp_hwif; /* protected by ide_cfg_mtx */
  433. ide_hwgroup_t *hwgroup;
  434. int irq_count = 0, unit;
  435. BUG_ON(index >= MAX_HWIFS);
  436. BUG_ON(in_interrupt());
  437. BUG_ON(irqs_disabled());
  438. mutex_lock(&ide_cfg_mtx);
  439. spin_lock_irq(&ide_lock);
  440. hwif = &ide_hwifs[index];
  441. if (!hwif->present)
  442. goto abort;
  443. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  444. drive = &hwif->drives[unit];
  445. if (!drive->present)
  446. continue;
  447. spin_unlock_irq(&ide_lock);
  448. device_unregister(&drive->gendev);
  449. wait_for_completion(&drive->gendev_rel_comp);
  450. spin_lock_irq(&ide_lock);
  451. }
  452. hwif->present = 0;
  453. spin_unlock_irq(&ide_lock);
  454. ide_proc_unregister_port(hwif);
  455. hwgroup = hwif->hwgroup;
  456. /*
  457. * free the irq if we were the only hwif using it
  458. */
  459. g = hwgroup->hwif;
  460. do {
  461. if (g->irq == hwif->irq)
  462. ++irq_count;
  463. g = g->next;
  464. } while (g != hwgroup->hwif);
  465. if (irq_count == 1)
  466. free_irq(hwif->irq, hwgroup);
  467. spin_lock_irq(&ide_lock);
  468. /*
  469. * Note that we only release the standard ports,
  470. * and do not even try to handle any extra ports
  471. * allocated for weird IDE interface chipsets.
  472. */
  473. ide_hwif_release_regions(hwif);
  474. /*
  475. * Remove us from the hwgroup, and free
  476. * the hwgroup if we were the only member
  477. */
  478. if (hwif->next == hwif) {
  479. BUG_ON(hwgroup->hwif != hwif);
  480. kfree(hwgroup);
  481. } else {
  482. /* There is another interface in hwgroup.
  483. * Unlink us, and set hwgroup->drive and ->hwif to
  484. * something sane.
  485. */
  486. g = hwgroup->hwif;
  487. while (g->next != hwif)
  488. g = g->next;
  489. g->next = hwif->next;
  490. if (hwgroup->hwif == hwif) {
  491. /* Chose a random hwif for hwgroup->hwif.
  492. * It's guaranteed that there are no drives
  493. * left in the hwgroup.
  494. */
  495. BUG_ON(hwgroup->drive != NULL);
  496. hwgroup->hwif = g;
  497. }
  498. BUG_ON(hwgroup->hwif == hwif);
  499. }
  500. /* More messed up locking ... */
  501. spin_unlock_irq(&ide_lock);
  502. device_unregister(&hwif->gendev);
  503. wait_for_completion(&hwif->gendev_rel_comp);
  504. /*
  505. * Remove us from the kernel's knowledge
  506. */
  507. blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
  508. kfree(hwif->sg_table);
  509. unregister_blkdev(hwif->major, hwif->name);
  510. spin_lock_irq(&ide_lock);
  511. if (hwif->dma_base) {
  512. (void) ide_release_dma(hwif);
  513. hwif->dma_base = 0;
  514. hwif->dma_command = 0;
  515. hwif->dma_vendor1 = 0;
  516. hwif->dma_status = 0;
  517. hwif->dma_vendor3 = 0;
  518. hwif->dma_prdtable = 0;
  519. hwif->extra_base = 0;
  520. hwif->extra_ports = 0;
  521. }
  522. /* copy original settings */
  523. tmp_hwif = *hwif;
  524. /* restore hwif data to pristine status */
  525. init_hwif_data(hwif, index);
  526. init_hwif_default(hwif, index);
  527. ide_hwif_restore(hwif, &tmp_hwif);
  528. abort:
  529. spin_unlock_irq(&ide_lock);
  530. mutex_unlock(&ide_cfg_mtx);
  531. }
  532. EXPORT_SYMBOL(ide_unregister);
  533. /**
  534. * ide_setup_ports - set up IDE interface ports
  535. * @hw: register descriptions
  536. * @base: base register
  537. * @offsets: table of register offsets
  538. * @ctrl: control register
  539. * @ack_irq: IRQ ack
  540. * @irq: interrupt lie
  541. *
  542. * Setup hw_regs_t structure described by parameters. You
  543. * may set up the hw structure yourself OR use this routine to
  544. * do it for you. This is basically a helper
  545. *
  546. */
  547. void ide_setup_ports ( hw_regs_t *hw,
  548. unsigned long base, int *offsets,
  549. unsigned long ctrl, unsigned long intr,
  550. ide_ack_intr_t *ack_intr,
  551. /*
  552. * ide_io_ops_t *iops,
  553. */
  554. int irq)
  555. {
  556. int i;
  557. memset(hw, 0, sizeof(hw_regs_t));
  558. for (i = 0; i < IDE_NR_PORTS; i++) {
  559. if (offsets[i] == -1) {
  560. switch(i) {
  561. case IDE_CONTROL_OFFSET:
  562. hw->io_ports[i] = ctrl;
  563. break;
  564. #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
  565. case IDE_IRQ_OFFSET:
  566. hw->io_ports[i] = intr;
  567. break;
  568. #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
  569. default:
  570. hw->io_ports[i] = 0;
  571. break;
  572. }
  573. } else {
  574. hw->io_ports[i] = base + offsets[i];
  575. }
  576. }
  577. hw->irq = irq;
  578. hw->ack_intr = ack_intr;
  579. /*
  580. * hw->iops = iops;
  581. */
  582. }
  583. /**
  584. * ide_register_hw - register IDE interface
  585. * @hw: hardware registers
  586. * @quirkproc: quirkproc function
  587. * @initializing: set while initializing built-in drivers
  588. * @hwifp: pointer to returned hwif
  589. *
  590. * Register an IDE interface, specifying exactly the registers etc.
  591. * Set init=1 iff calling before probes have taken place.
  592. *
  593. * Returns -1 on error.
  594. */
  595. int ide_register_hw(hw_regs_t *hw, void (*quirkproc)(ide_drive_t *),
  596. int initializing, ide_hwif_t **hwifp)
  597. {
  598. int index, retry = 1;
  599. ide_hwif_t *hwif;
  600. do {
  601. for (index = 0; index < MAX_HWIFS; ++index) {
  602. hwif = &ide_hwifs[index];
  603. if (hwif->io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
  604. goto found;
  605. }
  606. for (index = 0; index < MAX_HWIFS; ++index) {
  607. hwif = &ide_hwifs[index];
  608. if (hwif->hold)
  609. continue;
  610. if ((!hwif->present && !hwif->mate && !initializing) ||
  611. (!hwif->io_ports[IDE_DATA_OFFSET] && initializing))
  612. goto found;
  613. }
  614. for (index = 0; index < MAX_HWIFS; index++)
  615. ide_unregister(index);
  616. } while (retry--);
  617. return -1;
  618. found:
  619. if (hwif->present)
  620. ide_unregister(index);
  621. else if (!hwif->hold) {
  622. init_hwif_data(hwif, index);
  623. init_hwif_default(hwif, index);
  624. }
  625. if (hwif->present)
  626. return -1;
  627. memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
  628. hwif->irq = hw->irq;
  629. hwif->noprobe = 0;
  630. hwif->quirkproc = quirkproc;
  631. hwif->chipset = hw->chipset;
  632. hwif->gendev.parent = hw->dev;
  633. hwif->ack_intr = hw->ack_intr;
  634. if (initializing == 0) {
  635. u8 idx[4] = { index, 0xff, 0xff, 0xff };
  636. ide_device_add(idx);
  637. }
  638. if (hwifp)
  639. *hwifp = hwif;
  640. return (initializing || hwif->present) ? index : -1;
  641. }
  642. EXPORT_SYMBOL(ide_register_hw);
  643. /*
  644. * Locks for IDE setting functionality
  645. */
  646. DEFINE_MUTEX(ide_setting_mtx);
  647. EXPORT_SYMBOL_GPL(ide_setting_mtx);
  648. /**
  649. * ide_spin_wait_hwgroup - wait for group
  650. * @drive: drive in the group
  651. *
  652. * Wait for an IDE device group to go non busy and then return
  653. * holding the ide_lock which guards the hwgroup->busy status
  654. * and right to use it.
  655. */
  656. int ide_spin_wait_hwgroup (ide_drive_t *drive)
  657. {
  658. ide_hwgroup_t *hwgroup = HWGROUP(drive);
  659. unsigned long timeout = jiffies + (3 * HZ);
  660. spin_lock_irq(&ide_lock);
  661. while (hwgroup->busy) {
  662. unsigned long lflags;
  663. spin_unlock_irq(&ide_lock);
  664. local_irq_set(lflags);
  665. if (time_after(jiffies, timeout)) {
  666. local_irq_restore(lflags);
  667. printk(KERN_ERR "%s: channel busy\n", drive->name);
  668. return -EBUSY;
  669. }
  670. local_irq_restore(lflags);
  671. spin_lock_irq(&ide_lock);
  672. }
  673. return 0;
  674. }
  675. EXPORT_SYMBOL(ide_spin_wait_hwgroup);
  676. int set_io_32bit(ide_drive_t *drive, int arg)
  677. {
  678. if (drive->no_io_32bit)
  679. return -EPERM;
  680. if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
  681. return -EINVAL;
  682. if (ide_spin_wait_hwgroup(drive))
  683. return -EBUSY;
  684. drive->io_32bit = arg;
  685. #ifdef CONFIG_BLK_DEV_DTC2278
  686. if (HWIF(drive)->chipset == ide_dtc2278)
  687. HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
  688. #endif /* CONFIG_BLK_DEV_DTC2278 */
  689. spin_unlock_irq(&ide_lock);
  690. return 0;
  691. }
  692. static int set_ksettings(ide_drive_t *drive, int arg)
  693. {
  694. if (arg < 0 || arg > 1)
  695. return -EINVAL;
  696. if (ide_spin_wait_hwgroup(drive))
  697. return -EBUSY;
  698. drive->keep_settings = arg;
  699. spin_unlock_irq(&ide_lock);
  700. return 0;
  701. }
  702. int set_using_dma(ide_drive_t *drive, int arg)
  703. {
  704. #ifdef CONFIG_BLK_DEV_IDEDMA
  705. ide_hwif_t *hwif = drive->hwif;
  706. int err = -EPERM;
  707. if (arg < 0 || arg > 1)
  708. return -EINVAL;
  709. if (!drive->id || !(drive->id->capability & 1))
  710. goto out;
  711. if (hwif->dma_host_set == NULL)
  712. goto out;
  713. err = -EBUSY;
  714. if (ide_spin_wait_hwgroup(drive))
  715. goto out;
  716. /*
  717. * set ->busy flag, unlock and let it ride
  718. */
  719. hwif->hwgroup->busy = 1;
  720. spin_unlock_irq(&ide_lock);
  721. err = 0;
  722. if (arg) {
  723. if (ide_set_dma(drive))
  724. err = -EIO;
  725. } else
  726. ide_dma_off(drive);
  727. /*
  728. * lock, clear ->busy flag and unlock before leaving
  729. */
  730. spin_lock_irq(&ide_lock);
  731. hwif->hwgroup->busy = 0;
  732. spin_unlock_irq(&ide_lock);
  733. out:
  734. return err;
  735. #else
  736. if (arg < 0 || arg > 1)
  737. return -EINVAL;
  738. return -EPERM;
  739. #endif
  740. }
  741. int set_pio_mode(ide_drive_t *drive, int arg)
  742. {
  743. struct request rq;
  744. if (arg < 0 || arg > 255)
  745. return -EINVAL;
  746. if (drive->hwif->set_pio_mode == NULL)
  747. return -ENOSYS;
  748. if (drive->special.b.set_tune)
  749. return -EBUSY;
  750. ide_init_drive_cmd(&rq);
  751. drive->tune_req = (u8) arg;
  752. drive->special.b.set_tune = 1;
  753. (void) ide_do_drive_cmd(drive, &rq, ide_wait);
  754. return 0;
  755. }
  756. static int set_unmaskirq(ide_drive_t *drive, int arg)
  757. {
  758. if (drive->no_unmask)
  759. return -EPERM;
  760. if (arg < 0 || arg > 1)
  761. return -EINVAL;
  762. if (ide_spin_wait_hwgroup(drive))
  763. return -EBUSY;
  764. drive->unmask = arg;
  765. spin_unlock_irq(&ide_lock);
  766. return 0;
  767. }
  768. /**
  769. * system_bus_clock - clock guess
  770. *
  771. * External version of the bus clock guess used by very old IDE drivers
  772. * for things like VLB timings. Should not be used.
  773. */
  774. int system_bus_clock (void)
  775. {
  776. return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
  777. }
  778. EXPORT_SYMBOL(system_bus_clock);
  779. static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
  780. {
  781. ide_drive_t *drive = dev->driver_data;
  782. ide_hwif_t *hwif = HWIF(drive);
  783. struct request rq;
  784. struct request_pm_state rqpm;
  785. ide_task_t args;
  786. int ret;
  787. /* Call ACPI _GTM only once */
  788. if (!(drive->dn % 2))
  789. ide_acpi_get_timing(hwif);
  790. memset(&rq, 0, sizeof(rq));
  791. memset(&rqpm, 0, sizeof(rqpm));
  792. memset(&args, 0, sizeof(args));
  793. rq.cmd_type = REQ_TYPE_PM_SUSPEND;
  794. rq.special = &args;
  795. rq.data = &rqpm;
  796. rqpm.pm_step = ide_pm_state_start_suspend;
  797. if (mesg.event == PM_EVENT_PRETHAW)
  798. mesg.event = PM_EVENT_FREEZE;
  799. rqpm.pm_state = mesg.event;
  800. ret = ide_do_drive_cmd(drive, &rq, ide_wait);
  801. /* only call ACPI _PS3 after both drivers are suspended */
  802. if (!ret && (((drive->dn % 2) && hwif->drives[0].present
  803. && hwif->drives[1].present)
  804. || !hwif->drives[0].present
  805. || !hwif->drives[1].present))
  806. ide_acpi_set_state(hwif, 0);
  807. return ret;
  808. }
  809. static int generic_ide_resume(struct device *dev)
  810. {
  811. ide_drive_t *drive = dev->driver_data;
  812. ide_hwif_t *hwif = HWIF(drive);
  813. struct request rq;
  814. struct request_pm_state rqpm;
  815. ide_task_t args;
  816. int err;
  817. /* Call ACPI _STM only once */
  818. if (!(drive->dn % 2)) {
  819. ide_acpi_set_state(hwif, 1);
  820. ide_acpi_push_timing(hwif);
  821. }
  822. ide_acpi_exec_tfs(drive);
  823. memset(&rq, 0, sizeof(rq));
  824. memset(&rqpm, 0, sizeof(rqpm));
  825. memset(&args, 0, sizeof(args));
  826. rq.cmd_type = REQ_TYPE_PM_RESUME;
  827. rq.special = &args;
  828. rq.data = &rqpm;
  829. rqpm.pm_step = ide_pm_state_start_resume;
  830. rqpm.pm_state = PM_EVENT_ON;
  831. err = ide_do_drive_cmd(drive, &rq, ide_head_wait);
  832. if (err == 0 && dev->driver) {
  833. ide_driver_t *drv = to_ide_driver(dev->driver);
  834. if (drv->resume)
  835. drv->resume(drive);
  836. }
  837. return err;
  838. }
  839. int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
  840. unsigned int cmd, unsigned long arg)
  841. {
  842. unsigned long flags;
  843. ide_driver_t *drv;
  844. void __user *p = (void __user *)arg;
  845. int err = 0, (*setfunc)(ide_drive_t *, int);
  846. u8 *val;
  847. switch (cmd) {
  848. case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val;
  849. case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
  850. case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val;
  851. case HDIO_GET_DMA: val = &drive->using_dma; goto read_val;
  852. case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val;
  853. case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val;
  854. case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val;
  855. case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val;
  856. case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val;
  857. }
  858. switch (cmd) {
  859. case HDIO_OBSOLETE_IDENTITY:
  860. case HDIO_GET_IDENTITY:
  861. if (bdev != bdev->bd_contains)
  862. return -EINVAL;
  863. if (drive->id_read == 0)
  864. return -ENOMSG;
  865. if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
  866. return -EFAULT;
  867. return 0;
  868. case HDIO_GET_NICE:
  869. return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
  870. drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
  871. drive->nice0 << IDE_NICE_0 |
  872. drive->nice1 << IDE_NICE_1 |
  873. drive->nice2 << IDE_NICE_2,
  874. (long __user *) arg);
  875. #ifdef CONFIG_IDE_TASK_IOCTL
  876. case HDIO_DRIVE_TASKFILE:
  877. if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
  878. return -EACCES;
  879. switch(drive->media) {
  880. case ide_disk:
  881. return ide_taskfile_ioctl(drive, cmd, arg);
  882. default:
  883. return -ENOMSG;
  884. }
  885. #endif /* CONFIG_IDE_TASK_IOCTL */
  886. case HDIO_DRIVE_CMD:
  887. if (!capable(CAP_SYS_RAWIO))
  888. return -EACCES;
  889. return ide_cmd_ioctl(drive, cmd, arg);
  890. case HDIO_DRIVE_TASK:
  891. if (!capable(CAP_SYS_RAWIO))
  892. return -EACCES;
  893. return ide_task_ioctl(drive, cmd, arg);
  894. case HDIO_SCAN_HWIF:
  895. {
  896. hw_regs_t hw;
  897. int args[3];
  898. if (!capable(CAP_SYS_RAWIO)) return -EACCES;
  899. if (copy_from_user(args, p, 3 * sizeof(int)))
  900. return -EFAULT;
  901. memset(&hw, 0, sizeof(hw));
  902. ide_init_hwif_ports(&hw, (unsigned long) args[0],
  903. (unsigned long) args[1], NULL);
  904. hw.irq = args[2];
  905. if (ide_register_hw(&hw, NULL, 0, NULL) == -1)
  906. return -EIO;
  907. return 0;
  908. }
  909. case HDIO_UNREGISTER_HWIF:
  910. if (!capable(CAP_SYS_RAWIO)) return -EACCES;
  911. /* (arg > MAX_HWIFS) checked in function */
  912. ide_unregister(arg);
  913. return 0;
  914. case HDIO_SET_NICE:
  915. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  916. if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
  917. return -EPERM;
  918. drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
  919. drv = *(ide_driver_t **)bdev->bd_disk->private_data;
  920. if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
  921. drive->dsc_overlap = 0;
  922. return -EPERM;
  923. }
  924. drive->nice1 = (arg >> IDE_NICE_1) & 1;
  925. return 0;
  926. case HDIO_DRIVE_RESET:
  927. {
  928. unsigned long flags;
  929. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  930. /*
  931. * Abort the current command on the
  932. * group if there is one, taking
  933. * care not to allow anything else
  934. * to be queued and to die on the
  935. * spot if we miss one somehow
  936. */
  937. spin_lock_irqsave(&ide_lock, flags);
  938. if (HWGROUP(drive)->resetting) {
  939. spin_unlock_irqrestore(&ide_lock, flags);
  940. return -EBUSY;
  941. }
  942. ide_abort(drive, "drive reset");
  943. BUG_ON(HWGROUP(drive)->handler);
  944. /* Ensure nothing gets queued after we
  945. drop the lock. Reset will clear the busy */
  946. HWGROUP(drive)->busy = 1;
  947. spin_unlock_irqrestore(&ide_lock, flags);
  948. (void) ide_do_reset(drive);
  949. return 0;
  950. }
  951. case HDIO_GET_BUSSTATE:
  952. if (!capable(CAP_SYS_ADMIN))
  953. return -EACCES;
  954. if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
  955. return -EFAULT;
  956. return 0;
  957. case HDIO_SET_BUSSTATE:
  958. if (!capable(CAP_SYS_ADMIN))
  959. return -EACCES;
  960. if (HWIF(drive)->busproc)
  961. return HWIF(drive)->busproc(drive, (int)arg);
  962. return -EOPNOTSUPP;
  963. default:
  964. return -EINVAL;
  965. }
  966. read_val:
  967. mutex_lock(&ide_setting_mtx);
  968. spin_lock_irqsave(&ide_lock, flags);
  969. err = *val;
  970. spin_unlock_irqrestore(&ide_lock, flags);
  971. mutex_unlock(&ide_setting_mtx);
  972. return err >= 0 ? put_user(err, (long __user *)arg) : err;
  973. set_val:
  974. if (bdev != bdev->bd_contains)
  975. err = -EINVAL;
  976. else {
  977. if (!capable(CAP_SYS_ADMIN))
  978. err = -EACCES;
  979. else {
  980. mutex_lock(&ide_setting_mtx);
  981. err = setfunc(drive, arg);
  982. mutex_unlock(&ide_setting_mtx);
  983. }
  984. }
  985. return err;
  986. }
  987. EXPORT_SYMBOL(generic_ide_ioctl);
  988. /*
  989. * stridx() returns the offset of c within s,
  990. * or -1 if c is '\0' or not found within s.
  991. */
  992. static int __init stridx (const char *s, char c)
  993. {
  994. char *i = strchr(s, c);
  995. return (i && c) ? i - s : -1;
  996. }
  997. /*
  998. * match_parm() does parsing for ide_setup():
  999. *
  1000. * 1. the first char of s must be '='.
  1001. * 2. if the remainder matches one of the supplied keywords,
  1002. * the index (1 based) of the keyword is negated and returned.
  1003. * 3. if the remainder is a series of no more than max_vals numbers
  1004. * separated by commas, the numbers are saved in vals[] and a
  1005. * count of how many were saved is returned. Base10 is assumed,
  1006. * and base16 is allowed when prefixed with "0x".
  1007. * 4. otherwise, zero is returned.
  1008. */
  1009. static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
  1010. {
  1011. static const char *decimal = "0123456789";
  1012. static const char *hex = "0123456789abcdef";
  1013. int i, n;
  1014. if (*s++ == '=') {
  1015. /*
  1016. * Try matching against the supplied keywords,
  1017. * and return -(index+1) if we match one
  1018. */
  1019. if (keywords != NULL) {
  1020. for (i = 0; *keywords != NULL; ++i) {
  1021. if (!strcmp(s, *keywords++))
  1022. return -(i+1);
  1023. }
  1024. }
  1025. /*
  1026. * Look for a series of no more than "max_vals"
  1027. * numeric values separated by commas, in base10,
  1028. * or base16 when prefixed with "0x".
  1029. * Return a count of how many were found.
  1030. */
  1031. for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
  1032. vals[n] = i;
  1033. while ((i = stridx(decimal, *++s)) >= 0)
  1034. vals[n] = (vals[n] * 10) + i;
  1035. if (*s == 'x' && !vals[n]) {
  1036. while ((i = stridx(hex, *++s)) >= 0)
  1037. vals[n] = (vals[n] * 0x10) + i;
  1038. }
  1039. if (++n == max_vals)
  1040. break;
  1041. if (*s == ',' || *s == ';')
  1042. ++s;
  1043. }
  1044. if (!*s)
  1045. return n;
  1046. }
  1047. return 0; /* zero = nothing matched */
  1048. }
  1049. #ifdef CONFIG_BLK_DEV_ALI14XX
  1050. extern int probe_ali14xx;
  1051. extern int ali14xx_init(void);
  1052. #endif
  1053. #ifdef CONFIG_BLK_DEV_UMC8672
  1054. extern int probe_umc8672;
  1055. extern int umc8672_init(void);
  1056. #endif
  1057. #ifdef CONFIG_BLK_DEV_DTC2278
  1058. extern int probe_dtc2278;
  1059. extern int dtc2278_init(void);
  1060. #endif
  1061. #ifdef CONFIG_BLK_DEV_HT6560B
  1062. extern int probe_ht6560b;
  1063. extern int ht6560b_init(void);
  1064. #endif
  1065. #ifdef CONFIG_BLK_DEV_QD65XX
  1066. extern int probe_qd65xx;
  1067. extern int qd65xx_init(void);
  1068. #endif
  1069. static int __initdata is_chipset_set[MAX_HWIFS];
  1070. /*
  1071. * ide_setup() gets called VERY EARLY during initialization,
  1072. * to handle kernel "command line" strings beginning with "hdx=" or "ide".
  1073. *
  1074. * Remember to update Documentation/ide.txt if you change something here.
  1075. */
  1076. static int __init ide_setup(char *s)
  1077. {
  1078. int i, vals[3];
  1079. ide_hwif_t *hwif;
  1080. ide_drive_t *drive;
  1081. unsigned int hw, unit;
  1082. const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
  1083. const char max_hwif = '0' + (MAX_HWIFS - 1);
  1084. if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
  1085. return 0; /* driver and not us */
  1086. if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
  1087. return 0;
  1088. printk(KERN_INFO "ide_setup: %s", s);
  1089. init_ide_data ();
  1090. #ifdef CONFIG_BLK_DEV_IDEDOUBLER
  1091. if (!strcmp(s, "ide=doubler")) {
  1092. extern int ide_doubler;
  1093. printk(" : Enabled support for IDE doublers\n");
  1094. ide_doubler = 1;
  1095. return 1;
  1096. }
  1097. #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
  1098. if (!strcmp(s, "ide=nodma")) {
  1099. printk(" : Prevented DMA\n");
  1100. noautodma = 1;
  1101. goto obsolete_option;
  1102. }
  1103. #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
  1104. if (!strcmp(s, "ide=reverse")) {
  1105. ide_scan_direction = 1;
  1106. printk(" : Enabled support for IDE inverse scan order.\n");
  1107. return 1;
  1108. }
  1109. #endif
  1110. #ifdef CONFIG_BLK_DEV_IDEACPI
  1111. if (!strcmp(s, "ide=noacpi")) {
  1112. //printk(" : Disable IDE ACPI support.\n");
  1113. ide_noacpi = 1;
  1114. return 1;
  1115. }
  1116. if (!strcmp(s, "ide=acpigtf")) {
  1117. //printk(" : Enable IDE ACPI _GTF support.\n");
  1118. ide_noacpitfs = 0;
  1119. return 1;
  1120. }
  1121. if (!strcmp(s, "ide=acpionboot")) {
  1122. //printk(" : Call IDE ACPI methods on boot.\n");
  1123. ide_noacpionboot = 0;
  1124. return 1;
  1125. }
  1126. #endif /* CONFIG_BLK_DEV_IDEACPI */
  1127. /*
  1128. * Look for drive options: "hdx="
  1129. */
  1130. if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
  1131. const char *hd_words[] = {
  1132. "none", "noprobe", "nowerr", "cdrom", "nodma",
  1133. "autotune", "noautotune", "minus8", "swapdata", "bswap",
  1134. "noflush", "remap", "remap63", "scsi", NULL };
  1135. unit = s[2] - 'a';
  1136. hw = unit / MAX_DRIVES;
  1137. unit = unit % MAX_DRIVES;
  1138. hwif = &ide_hwifs[hw];
  1139. drive = &hwif->drives[unit];
  1140. if (strncmp(s + 4, "ide-", 4) == 0) {
  1141. strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
  1142. goto done;
  1143. }
  1144. switch (match_parm(&s[3], hd_words, vals, 3)) {
  1145. case -1: /* "none" */
  1146. case -2: /* "noprobe" */
  1147. drive->noprobe = 1;
  1148. goto done;
  1149. case -3: /* "nowerr" */
  1150. drive->bad_wstat = BAD_R_STAT;
  1151. hwif->noprobe = 0;
  1152. goto done;
  1153. case -4: /* "cdrom" */
  1154. drive->present = 1;
  1155. drive->media = ide_cdrom;
  1156. /* an ATAPI device ignores DRDY */
  1157. drive->ready_stat = 0;
  1158. hwif->noprobe = 0;
  1159. goto done;
  1160. case -5: /* nodma */
  1161. drive->nodma = 1;
  1162. goto done;
  1163. case -6: /* "autotune" */
  1164. drive->autotune = IDE_TUNE_AUTO;
  1165. goto obsolete_option;
  1166. case -7: /* "noautotune" */
  1167. drive->autotune = IDE_TUNE_NOAUTO;
  1168. goto obsolete_option;
  1169. case -9: /* "swapdata" */
  1170. case -10: /* "bswap" */
  1171. drive->bswap = 1;
  1172. goto done;
  1173. case -11: /* noflush */
  1174. drive->noflush = 1;
  1175. goto done;
  1176. case -12: /* "remap" */
  1177. drive->remap_0_to_1 = 1;
  1178. goto done;
  1179. case -13: /* "remap63" */
  1180. drive->sect0 = 63;
  1181. goto done;
  1182. case -14: /* "scsi" */
  1183. drive->scsi = 1;
  1184. goto done;
  1185. case 3: /* cyl,head,sect */
  1186. drive->media = ide_disk;
  1187. drive->ready_stat = READY_STAT;
  1188. drive->cyl = drive->bios_cyl = vals[0];
  1189. drive->head = drive->bios_head = vals[1];
  1190. drive->sect = drive->bios_sect = vals[2];
  1191. drive->present = 1;
  1192. drive->forced_geom = 1;
  1193. hwif->noprobe = 0;
  1194. goto done;
  1195. default:
  1196. goto bad_option;
  1197. }
  1198. }
  1199. if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
  1200. goto bad_option;
  1201. /*
  1202. * Look for bus speed option: "idebus="
  1203. */
  1204. if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
  1205. if (match_parm(&s[6], NULL, vals, 1) != 1)
  1206. goto bad_option;
  1207. if (vals[0] >= 20 && vals[0] <= 66) {
  1208. idebus_parameter = vals[0];
  1209. } else
  1210. printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
  1211. goto done;
  1212. }
  1213. /*
  1214. * Look for interface options: "idex="
  1215. */
  1216. if (s[3] >= '0' && s[3] <= max_hwif) {
  1217. /*
  1218. * Be VERY CAREFUL changing this: note hardcoded indexes below
  1219. * (-8, -9, -10) are reserved to ease the hardcoding.
  1220. */
  1221. static const char *ide_words[] = {
  1222. "noprobe", "serialize", "minus3", "minus4",
  1223. "reset", "minus6", "ata66", "minus8", "minus9",
  1224. "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
  1225. "dtc2278", "umc8672", "ali14xx", NULL };
  1226. hw_regs_t hwregs;
  1227. hw = s[3] - '0';
  1228. hwif = &ide_hwifs[hw];
  1229. i = match_parm(&s[4], ide_words, vals, 3);
  1230. /*
  1231. * Cryptic check to ensure chipset not already set for hwif.
  1232. * Note: we can't depend on hwif->chipset here.
  1233. */
  1234. if ((i >= -18 && i <= -11) || (i > 0 && i <= 3)) {
  1235. /* chipset already specified */
  1236. if (is_chipset_set[hw])
  1237. goto bad_option;
  1238. if (i > -18 && i <= -11) {
  1239. /* these drivers are for "ide0=" only */
  1240. if (hw != 0)
  1241. goto bad_hwif;
  1242. /* chipset already specified for 2nd port */
  1243. if (is_chipset_set[hw+1])
  1244. goto bad_option;
  1245. }
  1246. is_chipset_set[hw] = 1;
  1247. printk("\n");
  1248. }
  1249. switch (i) {
  1250. #ifdef CONFIG_BLK_DEV_ALI14XX
  1251. case -17: /* "ali14xx" */
  1252. probe_ali14xx = 1;
  1253. goto done;
  1254. #endif
  1255. #ifdef CONFIG_BLK_DEV_UMC8672
  1256. case -16: /* "umc8672" */
  1257. probe_umc8672 = 1;
  1258. goto done;
  1259. #endif
  1260. #ifdef CONFIG_BLK_DEV_DTC2278
  1261. case -15: /* "dtc2278" */
  1262. probe_dtc2278 = 1;
  1263. goto done;
  1264. #endif
  1265. #ifdef CONFIG_BLK_DEV_CMD640
  1266. case -14: /* "cmd640_vlb" */
  1267. {
  1268. extern int cmd640_vlb; /* flag for cmd640.c */
  1269. cmd640_vlb = 1;
  1270. goto done;
  1271. }
  1272. #endif
  1273. #ifdef CONFIG_BLK_DEV_HT6560B
  1274. case -13: /* "ht6560b" */
  1275. probe_ht6560b = 1;
  1276. goto done;
  1277. #endif
  1278. #ifdef CONFIG_BLK_DEV_QD65XX
  1279. case -12: /* "qd65xx" */
  1280. probe_qd65xx = 1;
  1281. goto done;
  1282. #endif
  1283. #ifdef CONFIG_BLK_DEV_4DRIVES
  1284. case -11: /* "four" drives on one set of ports */
  1285. {
  1286. ide_hwif_t *mate = &ide_hwifs[hw^1];
  1287. mate->drives[0].select.all ^= 0x20;
  1288. mate->drives[1].select.all ^= 0x20;
  1289. hwif->chipset = mate->chipset = ide_4drives;
  1290. mate->irq = hwif->irq;
  1291. memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
  1292. hwif->mate = mate;
  1293. mate->mate = hwif;
  1294. hwif->serialized = mate->serialized = 1;
  1295. goto obsolete_option;
  1296. }
  1297. #endif /* CONFIG_BLK_DEV_4DRIVES */
  1298. case -10: /* minus10 */
  1299. case -9: /* minus9 */
  1300. case -8: /* minus8 */
  1301. case -6:
  1302. case -4:
  1303. case -3:
  1304. goto bad_option;
  1305. case -7: /* ata66 */
  1306. #ifdef CONFIG_BLK_DEV_IDEPCI
  1307. /*
  1308. * Use ATA_CBL_PATA40_SHORT so drive side
  1309. * cable detection is also overriden.
  1310. */
  1311. hwif->cbl = ATA_CBL_PATA40_SHORT;
  1312. goto obsolete_option;
  1313. #else
  1314. goto bad_hwif;
  1315. #endif
  1316. case -5: /* "reset" */
  1317. hwif->reset = 1;
  1318. goto obsolete_option;
  1319. case -2: /* "serialize" */
  1320. hwif->mate = &ide_hwifs[hw^1];
  1321. hwif->mate->mate = hwif;
  1322. hwif->serialized = hwif->mate->serialized = 1;
  1323. goto obsolete_option;
  1324. case -1: /* "noprobe" */
  1325. hwif->noprobe = 1;
  1326. goto done;
  1327. case 1: /* base */
  1328. vals[1] = vals[0] + 0x206; /* default ctl */
  1329. case 2: /* base,ctl */
  1330. vals[2] = 0; /* default irq = probe for it */
  1331. case 3: /* base,ctl,irq */
  1332. memset(&hwregs, 0, sizeof(hwregs));
  1333. ide_init_hwif_ports(&hwregs, vals[0], vals[1], &hwif->irq);
  1334. memcpy(hwif->io_ports, hwregs.io_ports, sizeof(hwif->io_ports));
  1335. hwif->irq = vals[2];
  1336. hwif->noprobe = 0;
  1337. hwif->chipset = ide_forced;
  1338. goto obsolete_option;
  1339. case 0: goto bad_option;
  1340. default:
  1341. printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
  1342. return 1;
  1343. }
  1344. }
  1345. bad_option:
  1346. printk(" -- BAD OPTION\n");
  1347. return 1;
  1348. obsolete_option:
  1349. printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
  1350. return 1;
  1351. bad_hwif:
  1352. printk("-- NOT SUPPORTED ON ide%d", hw);
  1353. done:
  1354. printk("\n");
  1355. return 1;
  1356. }
  1357. extern void __init pnpide_init(void);
  1358. extern void __exit pnpide_exit(void);
  1359. extern void __init h8300_ide_init(void);
  1360. /*
  1361. * probe_for_hwifs() finds/initializes "known" IDE interfaces
  1362. */
  1363. static void __init probe_for_hwifs (void)
  1364. {
  1365. #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
  1366. ide_scan_pcibus(ide_scan_direction);
  1367. #endif
  1368. #ifdef CONFIG_ETRAX_IDE
  1369. {
  1370. extern void init_e100_ide(void);
  1371. init_e100_ide();
  1372. }
  1373. #endif /* CONFIG_ETRAX_IDE */
  1374. #ifdef CONFIG_BLK_DEV_CMD640
  1375. {
  1376. extern void ide_probe_for_cmd640x(void);
  1377. ide_probe_for_cmd640x();
  1378. }
  1379. #endif /* CONFIG_BLK_DEV_CMD640 */
  1380. #ifdef CONFIG_BLK_DEV_IDE_PMAC
  1381. {
  1382. extern int pmac_ide_probe(void);
  1383. (void)pmac_ide_probe();
  1384. }
  1385. #endif /* CONFIG_BLK_DEV_IDE_PMAC */
  1386. #ifdef CONFIG_BLK_DEV_GAYLE
  1387. {
  1388. extern void gayle_init(void);
  1389. gayle_init();
  1390. }
  1391. #endif /* CONFIG_BLK_DEV_GAYLE */
  1392. #ifdef CONFIG_BLK_DEV_FALCON_IDE
  1393. {
  1394. extern void falconide_init(void);
  1395. falconide_init();
  1396. }
  1397. #endif /* CONFIG_BLK_DEV_FALCON_IDE */
  1398. #ifdef CONFIG_BLK_DEV_MAC_IDE
  1399. {
  1400. extern void macide_init(void);
  1401. macide_init();
  1402. }
  1403. #endif /* CONFIG_BLK_DEV_MAC_IDE */
  1404. #ifdef CONFIG_BLK_DEV_Q40IDE
  1405. {
  1406. extern void q40ide_init(void);
  1407. q40ide_init();
  1408. }
  1409. #endif /* CONFIG_BLK_DEV_Q40IDE */
  1410. #ifdef CONFIG_BLK_DEV_BUDDHA
  1411. {
  1412. extern void buddha_init(void);
  1413. buddha_init();
  1414. }
  1415. #endif /* CONFIG_BLK_DEV_BUDDHA */
  1416. #ifdef CONFIG_BLK_DEV_IDEPNP
  1417. pnpide_init();
  1418. #endif
  1419. #ifdef CONFIG_H8300
  1420. h8300_ide_init();
  1421. #endif
  1422. }
  1423. /*
  1424. * Probe module
  1425. */
  1426. EXPORT_SYMBOL(ide_lock);
  1427. static int ide_bus_match(struct device *dev, struct device_driver *drv)
  1428. {
  1429. return 1;
  1430. }
  1431. static char *media_string(ide_drive_t *drive)
  1432. {
  1433. switch (drive->media) {
  1434. case ide_disk:
  1435. return "disk";
  1436. case ide_cdrom:
  1437. return "cdrom";
  1438. case ide_tape:
  1439. return "tape";
  1440. case ide_floppy:
  1441. return "floppy";
  1442. case ide_optical:
  1443. return "optical";
  1444. default:
  1445. return "UNKNOWN";
  1446. }
  1447. }
  1448. static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
  1449. {
  1450. ide_drive_t *drive = to_ide_device(dev);
  1451. return sprintf(buf, "%s\n", media_string(drive));
  1452. }
  1453. static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
  1454. {
  1455. ide_drive_t *drive = to_ide_device(dev);
  1456. return sprintf(buf, "%s\n", drive->name);
  1457. }
  1458. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
  1459. {
  1460. ide_drive_t *drive = to_ide_device(dev);
  1461. return sprintf(buf, "ide:m-%s\n", media_string(drive));
  1462. }
  1463. static ssize_t model_show(struct device *dev, struct device_attribute *attr,
  1464. char *buf)
  1465. {
  1466. ide_drive_t *drive = to_ide_device(dev);
  1467. return sprintf(buf, "%s\n", drive->id->model);
  1468. }
  1469. static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
  1470. char *buf)
  1471. {
  1472. ide_drive_t *drive = to_ide_device(dev);
  1473. return sprintf(buf, "%s\n", drive->id->fw_rev);
  1474. }
  1475. static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
  1476. char *buf)
  1477. {
  1478. ide_drive_t *drive = to_ide_device(dev);
  1479. return sprintf(buf, "%s\n", drive->id->serial_no);
  1480. }
  1481. static struct device_attribute ide_dev_attrs[] = {
  1482. __ATTR_RO(media),
  1483. __ATTR_RO(drivename),
  1484. __ATTR_RO(modalias),
  1485. __ATTR_RO(model),
  1486. __ATTR_RO(firmware),
  1487. __ATTR(serial, 0400, serial_show, NULL),
  1488. __ATTR_NULL
  1489. };
  1490. static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
  1491. {
  1492. ide_drive_t *drive = to_ide_device(dev);
  1493. add_uevent_var(env, "MEDIA=%s", media_string(drive));
  1494. add_uevent_var(env, "DRIVENAME=%s", drive->name);
  1495. add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive));
  1496. return 0;
  1497. }
  1498. static int generic_ide_probe(struct device *dev)
  1499. {
  1500. ide_drive_t *drive = to_ide_device(dev);
  1501. ide_driver_t *drv = to_ide_driver(dev->driver);
  1502. return drv->probe ? drv->probe(drive) : -ENODEV;
  1503. }
  1504. static int generic_ide_remove(struct device *dev)
  1505. {
  1506. ide_drive_t *drive = to_ide_device(dev);
  1507. ide_driver_t *drv = to_ide_driver(dev->driver);
  1508. if (drv->remove)
  1509. drv->remove(drive);
  1510. return 0;
  1511. }
  1512. static void generic_ide_shutdown(struct device *dev)
  1513. {
  1514. ide_drive_t *drive = to_ide_device(dev);
  1515. ide_driver_t *drv = to_ide_driver(dev->driver);
  1516. if (dev->driver && drv->shutdown)
  1517. drv->shutdown(drive);
  1518. }
  1519. struct bus_type ide_bus_type = {
  1520. .name = "ide",
  1521. .match = ide_bus_match,
  1522. .uevent = ide_uevent,
  1523. .probe = generic_ide_probe,
  1524. .remove = generic_ide_remove,
  1525. .shutdown = generic_ide_shutdown,
  1526. .dev_attrs = ide_dev_attrs,
  1527. .suspend = generic_ide_suspend,
  1528. .resume = generic_ide_resume,
  1529. };
  1530. EXPORT_SYMBOL_GPL(ide_bus_type);
  1531. /*
  1532. * This is gets invoked once during initialization, to set *everything* up
  1533. */
  1534. static int __init ide_init(void)
  1535. {
  1536. int ret;
  1537. printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
  1538. system_bus_speed = ide_system_bus_speed();
  1539. ret = bus_register(&ide_bus_type);
  1540. if (ret < 0) {
  1541. printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
  1542. return ret;
  1543. }
  1544. init_ide_data();
  1545. proc_ide_create();
  1546. #ifdef CONFIG_BLK_DEV_ALI14XX
  1547. if (probe_ali14xx)
  1548. (void)ali14xx_init();
  1549. #endif
  1550. #ifdef CONFIG_BLK_DEV_UMC8672
  1551. if (probe_umc8672)
  1552. (void)umc8672_init();
  1553. #endif
  1554. #ifdef CONFIG_BLK_DEV_DTC2278
  1555. if (probe_dtc2278)
  1556. (void)dtc2278_init();
  1557. #endif
  1558. #ifdef CONFIG_BLK_DEV_HT6560B
  1559. if (probe_ht6560b)
  1560. (void)ht6560b_init();
  1561. #endif
  1562. #ifdef CONFIG_BLK_DEV_QD65XX
  1563. if (probe_qd65xx)
  1564. (void)qd65xx_init();
  1565. #endif
  1566. /* Probe for special PCI and other "known" interface chipsets. */
  1567. probe_for_hwifs();
  1568. return 0;
  1569. }
  1570. #ifdef MODULE
  1571. static char *options = NULL;
  1572. module_param(options, charp, 0);
  1573. MODULE_LICENSE("GPL");
  1574. static void __init parse_options (char *line)
  1575. {
  1576. char *next = line;
  1577. if (line == NULL || !*line)
  1578. return;
  1579. while ((line = next) != NULL) {
  1580. if ((next = strchr(line,' ')) != NULL)
  1581. *next++ = 0;
  1582. if (!ide_setup(line))
  1583. printk (KERN_INFO "Unknown option '%s'\n", line);
  1584. }
  1585. }
  1586. int __init init_module (void)
  1587. {
  1588. parse_options(options);
  1589. return ide_init();
  1590. }
  1591. void __exit cleanup_module (void)
  1592. {
  1593. int index;
  1594. for (index = 0; index < MAX_HWIFS; ++index)
  1595. ide_unregister(index);
  1596. #ifdef CONFIG_BLK_DEV_IDEPNP
  1597. pnpide_exit();
  1598. #endif
  1599. proc_ide_destroy();
  1600. bus_unregister(&ide_bus_type);
  1601. }
  1602. #else /* !MODULE */
  1603. __setup("", ide_setup);
  1604. module_init(ide_init);
  1605. #endif /* MODULE */