ide.c 41 KB

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