ide.c 45 KB

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