ide.c 41 KB

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