ide.c 40 KB

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