ide.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012
  1. /*
  2. * linux/drivers/ide/ide.c Version 7.00beta2 Mar 05 2003
  3. *
  4. * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
  5. */
  6. /*
  7. * Mostly written by Mark Lord <mlord@pobox.com>
  8. * and Gadi Oxman <gadio@netvision.net.il>
  9. * and Andre Hedrick <andre@linux-ide.org>
  10. *
  11. * See linux/MAINTAINERS for address of current maintainer.
  12. *
  13. * This is the multiple IDE interface driver, as evolved from hd.c.
  14. * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs
  15. * (usually 14 & 15).
  16. * There can be up to two drives per interface, as per the ATA-2 spec.
  17. *
  18. * Primary: ide0, port 0x1f0; major=3; hda is minor=0; hdb is minor=64
  19. * Secondary: ide1, port 0x170; major=22; hdc is minor=0; hdd is minor=64
  20. * Tertiary: ide2, port 0x???; major=33; hde is minor=0; hdf is minor=64
  21. * Quaternary: ide3, port 0x???; major=34; hdg is minor=0; hdh is minor=64
  22. * ...
  23. *
  24. * From hd.c:
  25. * |
  26. * | It traverses the request-list, using interrupts to jump between functions.
  27. * | As nearly all functions can be called within interrupts, we may not sleep.
  28. * | Special care is recommended. Have Fun!
  29. * |
  30. * | modified by Drew Eckhardt to check nr of hd's from the CMOS.
  31. * |
  32. * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
  33. * | in the early extended-partition checks and added DM partitions.
  34. * |
  35. * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
  36. * |
  37. * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
  38. * | and general streamlining by Mark Lord (mlord@pobox.com).
  39. *
  40. * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
  41. *
  42. * Mark Lord (mlord@pobox.com) (IDE Perf.Pkg)
  43. * Delman Lee (delman@ieee.org) ("Mr. atdisk2")
  44. * Scott Snyder (snyder@fnald0.fnal.gov) (ATAPI IDE cd-rom)
  45. *
  46. * This was a rewrite of just about everything from hd.c, though some original
  47. * code is still sprinkled about. Think of it as a major evolution, with
  48. * inspiration from lots of linux users, esp. hamish@zot.apana.org.au
  49. *
  50. * Version 1.0 ALPHA initial code, primary i/f working okay
  51. * Version 1.3 BETA dual i/f on shared irq tested & working!
  52. * Version 1.4 BETA added auto probing for irq(s)
  53. * Version 1.5 BETA added ALPHA (untested) support for IDE cd-roms,
  54. * ...
  55. * Version 5.50 allow values as small as 20 for idebus=
  56. * Version 5.51 force non io_32bit in drive_cmd_intr()
  57. * change delay_10ms() to delay_50ms() to fix problems
  58. * Version 5.52 fix incorrect invalidation of removable devices
  59. * add "hdx=slow" command line option
  60. * Version 5.60 start to modularize the driver; the disk and ATAPI
  61. * drivers can be compiled as loadable modules.
  62. * move IDE probe code to ide-probe.c
  63. * move IDE disk code to ide-disk.c
  64. * add support for generic IDE device subdrivers
  65. * add m68k code from Geert Uytterhoeven
  66. * probe all interfaces by default
  67. * add ioctl to (re)probe an interface
  68. * Version 6.00 use per device request queues
  69. * attempt to optimize shared hwgroup performance
  70. * add ioctl to manually adjust bandwidth algorithms
  71. * add kerneld support for the probe module
  72. * fix bug in ide_error()
  73. * fix bug in the first ide_get_lock() call for Atari
  74. * don't flush leftover data for ATAPI devices
  75. * Version 6.01 clear hwgroup->active while the hwgroup sleeps
  76. * support HDIO_GETGEO for floppies
  77. * Version 6.02 fix ide_ack_intr() call
  78. * check partition table on floppies
  79. * Version 6.03 handle bad status bit sequencing in ide_wait_stat()
  80. * Version 6.10 deleted old entries from this list of updates
  81. * replaced triton.c with ide-dma.c generic PCI DMA
  82. * added support for BIOS-enabled UltraDMA
  83. * rename all "promise" things to "pdc4030"
  84. * fix EZ-DRIVE handling on small disks
  85. * Version 6.11 fix probe error in ide_scan_devices()
  86. * fix ancient "jiffies" polling bugs
  87. * mask all hwgroup interrupts on each irq entry
  88. * Version 6.12 integrate ioctl and proc interfaces
  89. * fix parsing of "idex=" command line parameter
  90. * Version 6.13 add support for ide4/ide5 courtesy rjones@orchestream.com
  91. * Version 6.14 fixed IRQ sharing among PCI devices
  92. * Version 6.15 added SMP awareness to IDE drivers
  93. * Version 6.16 fixed various bugs; even more SMP friendly
  94. * Version 6.17 fix for newest EZ-Drive problem
  95. * Version 6.18 default unpartitioned-disk translation now "BIOS LBA"
  96. * Version 6.19 Re-design for a UNIFORM driver for all platforms,
  97. * model based on suggestions from Russell King and
  98. * Geert Uytterhoeven
  99. * Promise DC4030VL now supported.
  100. * add support for ide6/ide7
  101. * delay_50ms() changed to ide_delay_50ms() and exported.
  102. * Version 6.20 Added/Fixed Generic ATA-66 support and hwif detection.
  103. * Added hdx=flash to allow for second flash disk
  104. * detection w/o the hang loop.
  105. * Added support for ide8/ide9
  106. * Added idex=ata66 for the quirky chipsets that are
  107. * ATA-66 compliant, but have yet to determine a method
  108. * of verification of the 80c cable presence.
  109. * Specifically Promise's PDC20262 chipset.
  110. * Version 6.21 Fixing/Fixed SMP spinlock issue with insight from an old
  111. * hat that clarified original low level driver design.
  112. * Version 6.30 Added SMP support; fixed multmode issues. -ml
  113. * Version 6.31 Debug Share INTR's and request queue streaming
  114. * Native ATA-100 support
  115. * Prep for Cascades Project
  116. * Version 7.00alpha First named revision of ide rearrange
  117. *
  118. * Some additional driver compile-time options are in ./include/linux/ide.h
  119. *
  120. * To do, in likely order of completion:
  121. * - modify kernel to obtain BIOS geometry for drives on 2nd/3rd/4th i/f
  122. *
  123. */
  124. #define REVISION "Revision: 7.00alpha2"
  125. #define VERSION "Id: ide.c 7.00a2 20020906"
  126. #undef REALLY_SLOW_IO /* most systems can safely undef this */
  127. #define _IDE_C /* Tell ide.h it's really us */
  128. #include <linux/config.h>
  129. #include <linux/module.h>
  130. #include <linux/types.h>
  131. #include <linux/string.h>
  132. #include <linux/kernel.h>
  133. #include <linux/timer.h>
  134. #include <linux/mm.h>
  135. #include <linux/interrupt.h>
  136. #include <linux/major.h>
  137. #include <linux/errno.h>
  138. #include <linux/genhd.h>
  139. #include <linux/blkpg.h>
  140. #include <linux/slab.h>
  141. #include <linux/init.h>
  142. #include <linux/pci.h>
  143. #include <linux/delay.h>
  144. #include <linux/ide.h>
  145. #include <linux/devfs_fs_kernel.h>
  146. #include <linux/completion.h>
  147. #include <linux/reboot.h>
  148. #include <linux/cdrom.h>
  149. #include <linux/seq_file.h>
  150. #include <linux/device.h>
  151. #include <linux/bitops.h>
  152. #include <asm/byteorder.h>
  153. #include <asm/irq.h>
  154. #include <asm/uaccess.h>
  155. #include <asm/io.h>
  156. /* default maximum number of failures */
  157. #define IDE_DEFAULT_MAX_FAILURES 1
  158. static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
  159. IDE2_MAJOR, IDE3_MAJOR,
  160. IDE4_MAJOR, IDE5_MAJOR,
  161. IDE6_MAJOR, IDE7_MAJOR,
  162. IDE8_MAJOR, IDE9_MAJOR };
  163. static int idebus_parameter; /* holds the "idebus=" parameter */
  164. static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */
  165. static int initializing; /* set while initializing built-in drivers */
  166. DECLARE_MUTEX(ide_cfg_sem);
  167. __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
  168. #ifdef CONFIG_BLK_DEV_IDEPCI
  169. static int ide_scan_direction; /* THIS was formerly 2.2.x pci=reverse */
  170. #endif
  171. #ifdef CONFIG_IDEDMA_AUTO
  172. int noautodma = 0;
  173. #else
  174. int noautodma = 1;
  175. #endif
  176. EXPORT_SYMBOL(noautodma);
  177. /*
  178. * This is declared extern in ide.h, for access by other IDE modules:
  179. */
  180. ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
  181. EXPORT_SYMBOL(ide_hwifs);
  182. /*
  183. * Do not even *think* about calling this!
  184. */
  185. static void init_hwif_data(ide_hwif_t *hwif, unsigned int index)
  186. {
  187. unsigned int unit;
  188. /* bulk initialize hwif & drive info with zeros */
  189. memset(hwif, 0, sizeof(ide_hwif_t));
  190. /* fill in any non-zero initial values */
  191. hwif->index = index;
  192. hwif->major = ide_hwif_to_major[index];
  193. hwif->name[0] = 'i';
  194. hwif->name[1] = 'd';
  195. hwif->name[2] = 'e';
  196. hwif->name[3] = '0' + index;
  197. hwif->bus_state = BUSSTATE_ON;
  198. hwif->atapi_dma = 0; /* disable all atapi dma */
  199. hwif->ultra_mask = 0x80; /* disable all ultra */
  200. hwif->mwdma_mask = 0x80; /* disable all mwdma */
  201. hwif->swdma_mask = 0x80; /* disable all swdma */
  202. sema_init(&hwif->gendev_rel_sem, 0);
  203. default_hwif_iops(hwif);
  204. default_hwif_transport(hwif);
  205. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  206. ide_drive_t *drive = &hwif->drives[unit];
  207. drive->media = ide_disk;
  208. drive->select.all = (unit<<4)|0xa0;
  209. drive->hwif = hwif;
  210. drive->ctl = 0x08;
  211. drive->ready_stat = READY_STAT;
  212. drive->bad_wstat = BAD_W_STAT;
  213. drive->special.b.recalibrate = 1;
  214. drive->special.b.set_geometry = 1;
  215. drive->name[0] = 'h';
  216. drive->name[1] = 'd';
  217. drive->name[2] = 'a' + (index * MAX_DRIVES) + unit;
  218. drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
  219. drive->using_dma = 0;
  220. drive->is_flash = 0;
  221. drive->vdma = 0;
  222. INIT_LIST_HEAD(&drive->list);
  223. sema_init(&drive->gendev_rel_sem, 0);
  224. }
  225. }
  226. static void init_hwif_default(ide_hwif_t *hwif, unsigned int index)
  227. {
  228. hw_regs_t hw;
  229. memset(&hw, 0, sizeof(hw_regs_t));
  230. ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
  231. memcpy(&hwif->hw, &hw, sizeof(hw));
  232. memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
  233. hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
  234. #ifdef CONFIG_BLK_DEV_HD
  235. if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)
  236. hwif->noprobe = 1; /* may be overridden by ide_setup() */
  237. #endif
  238. }
  239. extern void ide_arm_init(void);
  240. /*
  241. * init_ide_data() sets reasonable default values into all fields
  242. * of all instances of the hwifs and drives, but only on the first call.
  243. * Subsequent calls have no effect (they don't wipe out anything).
  244. *
  245. * This routine is normally called at driver initialization time,
  246. * but may also be called MUCH earlier during kernel "command-line"
  247. * parameter processing. As such, we cannot depend on any other parts
  248. * of the kernel (such as memory allocation) to be functioning yet.
  249. *
  250. * This is too bad, as otherwise we could dynamically allocate the
  251. * ide_drive_t structs as needed, rather than always consuming memory
  252. * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
  253. *
  254. * FIXME: We should stuff the setup data into __init and copy the
  255. * relevant hwifs/allocate them properly during boot.
  256. */
  257. #define MAGIC_COOKIE 0x12345678
  258. static void __init init_ide_data (void)
  259. {
  260. ide_hwif_t *hwif;
  261. unsigned int index;
  262. static unsigned long magic_cookie = MAGIC_COOKIE;
  263. if (magic_cookie != MAGIC_COOKIE)
  264. return; /* already initialized */
  265. magic_cookie = 0;
  266. /* Initialise all interface structures */
  267. for (index = 0; index < MAX_HWIFS; ++index) {
  268. hwif = &ide_hwifs[index];
  269. init_hwif_data(hwif, index);
  270. init_hwif_default(hwif, index);
  271. #if !defined(CONFIG_PPC32) || !defined(CONFIG_PCI)
  272. hwif->irq = hwif->hw.irq =
  273. ide_init_default_irq(hwif->io_ports[IDE_DATA_OFFSET]);
  274. #endif
  275. }
  276. #ifdef CONFIG_IDE_ARM
  277. initializing = 1;
  278. ide_arm_init();
  279. initializing = 0;
  280. #endif
  281. }
  282. /**
  283. * ide_system_bus_speed - guess bus speed
  284. *
  285. * ide_system_bus_speed() returns what we think is the system VESA/PCI
  286. * bus speed (in MHz). This is used for calculating interface PIO timings.
  287. * The default is 40 for known PCI systems, 50 otherwise.
  288. * The "idebus=xx" parameter can be used to override this value.
  289. * The actual value to be used is computed/displayed the first time
  290. * through. Drivers should only use this as a last resort.
  291. *
  292. * Returns a guessed speed in MHz.
  293. */
  294. static int ide_system_bus_speed(void)
  295. {
  296. #ifdef CONFIG_PCI
  297. static struct pci_device_id pci_default[] = {
  298. { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) },
  299. { }
  300. };
  301. #else
  302. #define pci_default 0
  303. #endif /* CONFIG_PCI */
  304. if (!system_bus_speed) {
  305. if (idebus_parameter) {
  306. /* user supplied value */
  307. system_bus_speed = idebus_parameter;
  308. } else if (pci_dev_present(pci_default)) {
  309. /* safe default value for PCI */
  310. system_bus_speed = 33;
  311. } else {
  312. /* safe default value for VESA and PCI */
  313. system_bus_speed = 50;
  314. }
  315. printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
  316. "for PIO modes%s\n", system_bus_speed,
  317. idebus_parameter ? "" : "; override with idebus=xx");
  318. }
  319. return system_bus_speed;
  320. }
  321. #ifdef CONFIG_PROC_FS
  322. struct proc_dir_entry *proc_ide_root;
  323. #endif
  324. static struct resource* hwif_request_region(ide_hwif_t *hwif,
  325. unsigned long addr, int num)
  326. {
  327. struct resource *res = request_region(addr, num, hwif->name);
  328. if (!res)
  329. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
  330. hwif->name, addr, addr+num-1);
  331. return res;
  332. }
  333. /**
  334. * ide_hwif_request_regions - request resources for IDE
  335. * @hwif: interface to use
  336. *
  337. * Requests all the needed resources for an interface.
  338. * Right now core IDE code does this work which is deeply wrong.
  339. * MMIO leaves it to the controller driver,
  340. * PIO will migrate this way over time.
  341. */
  342. int ide_hwif_request_regions(ide_hwif_t *hwif)
  343. {
  344. unsigned long addr;
  345. unsigned int i;
  346. if (hwif->mmio == 2)
  347. return 0;
  348. BUG_ON(hwif->mmio == 1);
  349. addr = hwif->io_ports[IDE_CONTROL_OFFSET];
  350. if (addr && !hwif_request_region(hwif, addr, 1))
  351. goto control_region_busy;
  352. hwif->straight8 = 0;
  353. addr = hwif->io_ports[IDE_DATA_OFFSET];
  354. if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) {
  355. if (!hwif_request_region(hwif, addr, 8))
  356. goto data_region_busy;
  357. hwif->straight8 = 1;
  358. return 0;
  359. }
  360. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
  361. addr = hwif->io_ports[i];
  362. if (!hwif_request_region(hwif, addr, 1)) {
  363. while (--i)
  364. release_region(addr, 1);
  365. goto data_region_busy;
  366. }
  367. }
  368. return 0;
  369. data_region_busy:
  370. addr = hwif->io_ports[IDE_CONTROL_OFFSET];
  371. if (addr)
  372. release_region(addr, 1);
  373. control_region_busy:
  374. /* If any errors are return, we drop the hwif interface. */
  375. return -EBUSY;
  376. }
  377. /**
  378. * ide_hwif_release_regions - free IDE resources
  379. *
  380. * Note that we only release the standard ports,
  381. * and do not even try to handle any extra ports
  382. * allocated for weird IDE interface chipsets.
  383. *
  384. * Note also that we don't yet handle mmio resources here. More
  385. * importantly our caller should be doing this so we need to
  386. * restructure this as a helper function for drivers.
  387. */
  388. void ide_hwif_release_regions(ide_hwif_t *hwif)
  389. {
  390. u32 i = 0;
  391. if (hwif->mmio == 2)
  392. return;
  393. if (hwif->io_ports[IDE_CONTROL_OFFSET])
  394. release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
  395. if (hwif->straight8) {
  396. release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
  397. return;
  398. }
  399. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
  400. if (hwif->io_ports[i])
  401. release_region(hwif->io_ports[i], 1);
  402. }
  403. /**
  404. * ide_hwif_restore - restore hwif to template
  405. * @hwif: hwif to update
  406. * @tmp_hwif: template
  407. *
  408. * Restore hwif to a previous state by copying most settngs
  409. * from the template.
  410. */
  411. static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
  412. {
  413. hwif->hwgroup = tmp_hwif->hwgroup;
  414. hwif->gendev.parent = tmp_hwif->gendev.parent;
  415. hwif->proc = tmp_hwif->proc;
  416. hwif->major = tmp_hwif->major;
  417. hwif->straight8 = tmp_hwif->straight8;
  418. hwif->bus_state = tmp_hwif->bus_state;
  419. hwif->atapi_dma = tmp_hwif->atapi_dma;
  420. hwif->ultra_mask = tmp_hwif->ultra_mask;
  421. hwif->mwdma_mask = tmp_hwif->mwdma_mask;
  422. hwif->swdma_mask = tmp_hwif->swdma_mask;
  423. hwif->chipset = tmp_hwif->chipset;
  424. hwif->hold = tmp_hwif->hold;
  425. #ifdef CONFIG_BLK_DEV_IDEPCI
  426. hwif->pci_dev = tmp_hwif->pci_dev;
  427. hwif->cds = tmp_hwif->cds;
  428. #endif
  429. hwif->tuneproc = tmp_hwif->tuneproc;
  430. hwif->speedproc = tmp_hwif->speedproc;
  431. hwif->selectproc = tmp_hwif->selectproc;
  432. hwif->reset_poll = tmp_hwif->reset_poll;
  433. hwif->pre_reset = tmp_hwif->pre_reset;
  434. hwif->resetproc = tmp_hwif->resetproc;
  435. hwif->intrproc = tmp_hwif->intrproc;
  436. hwif->maskproc = tmp_hwif->maskproc;
  437. hwif->quirkproc = tmp_hwif->quirkproc;
  438. hwif->busproc = tmp_hwif->busproc;
  439. hwif->ata_input_data = tmp_hwif->ata_input_data;
  440. hwif->ata_output_data = tmp_hwif->ata_output_data;
  441. hwif->atapi_input_bytes = tmp_hwif->atapi_input_bytes;
  442. hwif->atapi_output_bytes = tmp_hwif->atapi_output_bytes;
  443. hwif->dma_setup = tmp_hwif->dma_setup;
  444. hwif->dma_exec_cmd = tmp_hwif->dma_exec_cmd;
  445. hwif->dma_start = tmp_hwif->dma_start;
  446. hwif->ide_dma_end = tmp_hwif->ide_dma_end;
  447. hwif->ide_dma_check = tmp_hwif->ide_dma_check;
  448. hwif->ide_dma_on = tmp_hwif->ide_dma_on;
  449. hwif->ide_dma_off_quietly = tmp_hwif->ide_dma_off_quietly;
  450. hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq;
  451. hwif->ide_dma_host_on = tmp_hwif->ide_dma_host_on;
  452. hwif->ide_dma_host_off = tmp_hwif->ide_dma_host_off;
  453. hwif->ide_dma_lostirq = tmp_hwif->ide_dma_lostirq;
  454. hwif->ide_dma_timeout = tmp_hwif->ide_dma_timeout;
  455. hwif->OUTB = tmp_hwif->OUTB;
  456. hwif->OUTBSYNC = tmp_hwif->OUTBSYNC;
  457. hwif->OUTW = tmp_hwif->OUTW;
  458. hwif->OUTL = tmp_hwif->OUTL;
  459. hwif->OUTSW = tmp_hwif->OUTSW;
  460. hwif->OUTSL = tmp_hwif->OUTSL;
  461. hwif->INB = tmp_hwif->INB;
  462. hwif->INW = tmp_hwif->INW;
  463. hwif->INL = tmp_hwif->INL;
  464. hwif->INSW = tmp_hwif->INSW;
  465. hwif->INSL = tmp_hwif->INSL;
  466. hwif->sg_max_nents = tmp_hwif->sg_max_nents;
  467. hwif->mmio = tmp_hwif->mmio;
  468. hwif->rqsize = tmp_hwif->rqsize;
  469. hwif->no_lba48 = tmp_hwif->no_lba48;
  470. #ifndef CONFIG_BLK_DEV_IDECS
  471. hwif->irq = tmp_hwif->irq;
  472. #endif
  473. hwif->dma_base = tmp_hwif->dma_base;
  474. hwif->dma_master = tmp_hwif->dma_master;
  475. hwif->dma_command = tmp_hwif->dma_command;
  476. hwif->dma_vendor1 = tmp_hwif->dma_vendor1;
  477. hwif->dma_status = tmp_hwif->dma_status;
  478. hwif->dma_vendor3 = tmp_hwif->dma_vendor3;
  479. hwif->dma_prdtable = tmp_hwif->dma_prdtable;
  480. hwif->dma_extra = tmp_hwif->dma_extra;
  481. hwif->config_data = tmp_hwif->config_data;
  482. hwif->select_data = tmp_hwif->select_data;
  483. hwif->autodma = tmp_hwif->autodma;
  484. hwif->udma_four = tmp_hwif->udma_four;
  485. hwif->no_dsc = tmp_hwif->no_dsc;
  486. hwif->hwif_data = tmp_hwif->hwif_data;
  487. }
  488. /**
  489. * ide_unregister - free an ide interface
  490. * @index: index of interface (will change soon to a pointer)
  491. *
  492. * Perform the final unregister of an IDE interface. At the moment
  493. * we don't refcount interfaces so this will also get split up.
  494. *
  495. * Locking:
  496. * The caller must not hold the IDE locks
  497. * The drive present/vanishing is not yet properly locked
  498. * Take care with the callbacks. These have been split to avoid
  499. * deadlocking the IDE layer. The shutdown callback is called
  500. * before we take the lock and free resources. It is up to the
  501. * caller to be sure there is no pending I/O here, and that
  502. * the interfce will not be reopened (present/vanishing locking
  503. * isnt yet done btw). After we commit to the final kill we
  504. * call the cleanup callback with the ide locks held.
  505. *
  506. * Unregister restores the hwif structures to the default state.
  507. * This is raving bonkers.
  508. */
  509. void ide_unregister(unsigned int index)
  510. {
  511. ide_drive_t *drive;
  512. ide_hwif_t *hwif, *g;
  513. static ide_hwif_t tmp_hwif; /* protected by ide_cfg_sem */
  514. ide_hwgroup_t *hwgroup;
  515. int irq_count = 0, unit;
  516. BUG_ON(index >= MAX_HWIFS);
  517. BUG_ON(in_interrupt());
  518. BUG_ON(irqs_disabled());
  519. down(&ide_cfg_sem);
  520. spin_lock_irq(&ide_lock);
  521. hwif = &ide_hwifs[index];
  522. if (!hwif->present)
  523. goto abort;
  524. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  525. drive = &hwif->drives[unit];
  526. if (!drive->present) {
  527. if (drive->devfs_name[0] != '\0') {
  528. devfs_remove(drive->devfs_name);
  529. drive->devfs_name[0] = '\0';
  530. }
  531. continue;
  532. }
  533. spin_unlock_irq(&ide_lock);
  534. device_unregister(&drive->gendev);
  535. down(&drive->gendev_rel_sem);
  536. spin_lock_irq(&ide_lock);
  537. }
  538. hwif->present = 0;
  539. spin_unlock_irq(&ide_lock);
  540. destroy_proc_ide_interface(hwif);
  541. hwgroup = hwif->hwgroup;
  542. /*
  543. * free the irq if we were the only hwif using it
  544. */
  545. g = hwgroup->hwif;
  546. do {
  547. if (g->irq == hwif->irq)
  548. ++irq_count;
  549. g = g->next;
  550. } while (g != hwgroup->hwif);
  551. if (irq_count == 1)
  552. free_irq(hwif->irq, hwgroup);
  553. spin_lock_irq(&ide_lock);
  554. /*
  555. * Note that we only release the standard ports,
  556. * and do not even try to handle any extra ports
  557. * allocated for weird IDE interface chipsets.
  558. */
  559. ide_hwif_release_regions(hwif);
  560. /*
  561. * Remove us from the hwgroup, and free
  562. * the hwgroup if we were the only member
  563. */
  564. if (hwif->next == hwif) {
  565. BUG_ON(hwgroup->hwif != hwif);
  566. kfree(hwgroup);
  567. } else {
  568. /* There is another interface in hwgroup.
  569. * Unlink us, and set hwgroup->drive and ->hwif to
  570. * something sane.
  571. */
  572. g = hwgroup->hwif;
  573. while (g->next != hwif)
  574. g = g->next;
  575. g->next = hwif->next;
  576. if (hwgroup->hwif == hwif) {
  577. /* Chose a random hwif for hwgroup->hwif.
  578. * It's guaranteed that there are no drives
  579. * left in the hwgroup.
  580. */
  581. BUG_ON(hwgroup->drive != NULL);
  582. hwgroup->hwif = g;
  583. }
  584. BUG_ON(hwgroup->hwif == hwif);
  585. }
  586. /* More messed up locking ... */
  587. spin_unlock_irq(&ide_lock);
  588. device_unregister(&hwif->gendev);
  589. down(&hwif->gendev_rel_sem);
  590. /*
  591. * Remove us from the kernel's knowledge
  592. */
  593. blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
  594. kfree(hwif->sg_table);
  595. unregister_blkdev(hwif->major, hwif->name);
  596. spin_lock_irq(&ide_lock);
  597. if (hwif->dma_base) {
  598. (void) ide_release_dma(hwif);
  599. hwif->dma_base = 0;
  600. hwif->dma_master = 0;
  601. hwif->dma_command = 0;
  602. hwif->dma_vendor1 = 0;
  603. hwif->dma_status = 0;
  604. hwif->dma_vendor3 = 0;
  605. hwif->dma_prdtable = 0;
  606. }
  607. /* copy original settings */
  608. tmp_hwif = *hwif;
  609. /* restore hwif data to pristine status */
  610. init_hwif_data(hwif, index);
  611. init_hwif_default(hwif, index);
  612. ide_hwif_restore(hwif, &tmp_hwif);
  613. abort:
  614. spin_unlock_irq(&ide_lock);
  615. up(&ide_cfg_sem);
  616. }
  617. EXPORT_SYMBOL(ide_unregister);
  618. /**
  619. * ide_setup_ports - set up IDE interface ports
  620. * @hw: register descriptions
  621. * @base: base register
  622. * @offsets: table of register offsets
  623. * @ctrl: control register
  624. * @ack_irq: IRQ ack
  625. * @irq: interrupt lie
  626. *
  627. * Setup hw_regs_t structure described by parameters. You
  628. * may set up the hw structure yourself OR use this routine to
  629. * do it for you. This is basically a helper
  630. *
  631. */
  632. void ide_setup_ports ( hw_regs_t *hw,
  633. unsigned long base, int *offsets,
  634. unsigned long ctrl, unsigned long intr,
  635. ide_ack_intr_t *ack_intr,
  636. /*
  637. * ide_io_ops_t *iops,
  638. */
  639. int irq)
  640. {
  641. int i;
  642. for (i = 0; i < IDE_NR_PORTS; i++) {
  643. if (offsets[i] == -1) {
  644. switch(i) {
  645. case IDE_CONTROL_OFFSET:
  646. hw->io_ports[i] = ctrl;
  647. break;
  648. #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
  649. case IDE_IRQ_OFFSET:
  650. hw->io_ports[i] = intr;
  651. break;
  652. #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
  653. default:
  654. hw->io_ports[i] = 0;
  655. break;
  656. }
  657. } else {
  658. hw->io_ports[i] = base + offsets[i];
  659. }
  660. }
  661. hw->irq = irq;
  662. hw->dma = NO_DMA;
  663. hw->ack_intr = ack_intr;
  664. /*
  665. * hw->iops = iops;
  666. */
  667. }
  668. /**
  669. * ide_register_hw_with_fixup - register IDE interface
  670. * @hw: hardware registers
  671. * @hwifp: pointer to returned hwif
  672. * @fixup: fixup function
  673. *
  674. * Register an IDE interface, specifying exactly the registers etc.
  675. * Set init=1 iff calling before probes have taken place.
  676. *
  677. * Returns -1 on error.
  678. */
  679. int ide_register_hw_with_fixup(hw_regs_t *hw, ide_hwif_t **hwifp, void(*fixup)(ide_hwif_t *hwif))
  680. {
  681. int index, retry = 1;
  682. ide_hwif_t *hwif;
  683. do {
  684. for (index = 0; index < MAX_HWIFS; ++index) {
  685. hwif = &ide_hwifs[index];
  686. if (hwif->hw.io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
  687. goto found;
  688. }
  689. for (index = 0; index < MAX_HWIFS; ++index) {
  690. hwif = &ide_hwifs[index];
  691. if (hwif->hold)
  692. continue;
  693. if ((!hwif->present && !hwif->mate && !initializing) ||
  694. (!hwif->hw.io_ports[IDE_DATA_OFFSET] && initializing))
  695. goto found;
  696. }
  697. for (index = 0; index < MAX_HWIFS; index++)
  698. ide_unregister(index);
  699. } while (retry--);
  700. return -1;
  701. found:
  702. if (hwif->present)
  703. ide_unregister(index);
  704. else if (!hwif->hold) {
  705. init_hwif_data(hwif, index);
  706. init_hwif_default(hwif, index);
  707. }
  708. if (hwif->present)
  709. return -1;
  710. memcpy(&hwif->hw, hw, sizeof(*hw));
  711. memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->hw.io_ports));
  712. hwif->irq = hw->irq;
  713. hwif->noprobe = 0;
  714. hwif->chipset = hw->chipset;
  715. if (!initializing) {
  716. probe_hwif_init_with_fixup(hwif, fixup);
  717. create_proc_ide_interfaces();
  718. }
  719. if (hwifp)
  720. *hwifp = hwif;
  721. return (initializing || hwif->present) ? index : -1;
  722. }
  723. EXPORT_SYMBOL(ide_register_hw_with_fixup);
  724. int ide_register_hw(hw_regs_t *hw, ide_hwif_t **hwifp)
  725. {
  726. return ide_register_hw_with_fixup(hw, hwifp, NULL);
  727. }
  728. EXPORT_SYMBOL(ide_register_hw);
  729. /*
  730. * Locks for IDE setting functionality
  731. */
  732. DECLARE_MUTEX(ide_setting_sem);
  733. /**
  734. * __ide_add_setting - add an ide setting option
  735. * @drive: drive to use
  736. * @name: setting name
  737. * @rw: true if the function is read write
  738. * @read_ioctl: function to call on read
  739. * @write_ioctl: function to call on write
  740. * @data_type: type of data
  741. * @min: range minimum
  742. * @max: range maximum
  743. * @mul_factor: multiplication scale
  744. * @div_factor: divison scale
  745. * @data: private data field
  746. * @set: setting
  747. * @auto_remove: setting auto removal flag
  748. *
  749. * Removes the setting named from the device if it is present.
  750. * The function takes the settings_lock to protect against
  751. * parallel changes. This function must not be called from IRQ
  752. * context. Returns 0 on success or -1 on failure.
  753. *
  754. * BUGS: This code is seriously over-engineered. There is also
  755. * magic about how the driver specific features are setup. If
  756. * a driver is attached we assume the driver settings are auto
  757. * remove.
  758. */
  759. static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set, int auto_remove)
  760. {
  761. ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
  762. down(&ide_setting_sem);
  763. while ((*p) && strcmp((*p)->name, name) < 0)
  764. p = &((*p)->next);
  765. if ((setting = kmalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
  766. goto abort;
  767. memset(setting, 0, sizeof(*setting));
  768. if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
  769. goto abort;
  770. strcpy(setting->name, name);
  771. setting->rw = rw;
  772. setting->read_ioctl = read_ioctl;
  773. setting->write_ioctl = write_ioctl;
  774. setting->data_type = data_type;
  775. setting->min = min;
  776. setting->max = max;
  777. setting->mul_factor = mul_factor;
  778. setting->div_factor = div_factor;
  779. setting->data = data;
  780. setting->set = set;
  781. setting->next = *p;
  782. if (auto_remove)
  783. setting->auto_remove = 1;
  784. *p = setting;
  785. up(&ide_setting_sem);
  786. return 0;
  787. abort:
  788. up(&ide_setting_sem);
  789. if (setting)
  790. kfree(setting);
  791. return -1;
  792. }
  793. int ide_add_setting(ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set)
  794. {
  795. return __ide_add_setting(drive, name, rw, read_ioctl, write_ioctl, data_type, min, max, mul_factor, div_factor, data, set, 1);
  796. }
  797. EXPORT_SYMBOL(ide_add_setting);
  798. /**
  799. * __ide_remove_setting - remove an ide setting option
  800. * @drive: drive to use
  801. * @name: setting name
  802. *
  803. * Removes the setting named from the device if it is present.
  804. * The caller must hold the setting semaphore.
  805. */
  806. static void __ide_remove_setting (ide_drive_t *drive, char *name)
  807. {
  808. ide_settings_t **p, *setting;
  809. p = (ide_settings_t **) &drive->settings;
  810. while ((*p) && strcmp((*p)->name, name))
  811. p = &((*p)->next);
  812. if ((setting = (*p)) == NULL)
  813. return;
  814. (*p) = setting->next;
  815. kfree(setting->name);
  816. kfree(setting);
  817. }
  818. /**
  819. * ide_find_setting_by_ioctl - find a drive specific ioctl
  820. * @drive: drive to scan
  821. * @cmd: ioctl command to handle
  822. *
  823. * Scan's the device setting table for a matching entry and returns
  824. * this or NULL if no entry is found. The caller must hold the
  825. * setting semaphore
  826. */
  827. static ide_settings_t *ide_find_setting_by_ioctl (ide_drive_t *drive, int cmd)
  828. {
  829. ide_settings_t *setting = drive->settings;
  830. while (setting) {
  831. if (setting->read_ioctl == cmd || setting->write_ioctl == cmd)
  832. break;
  833. setting = setting->next;
  834. }
  835. return setting;
  836. }
  837. /**
  838. * ide_find_setting_by_name - find a drive specific setting
  839. * @drive: drive to scan
  840. * @name: setting name
  841. *
  842. * Scan's the device setting table for a matching entry and returns
  843. * this or NULL if no entry is found. The caller must hold the
  844. * setting semaphore
  845. */
  846. ide_settings_t *ide_find_setting_by_name (ide_drive_t *drive, char *name)
  847. {
  848. ide_settings_t *setting = drive->settings;
  849. while (setting) {
  850. if (strcmp(setting->name, name) == 0)
  851. break;
  852. setting = setting->next;
  853. }
  854. return setting;
  855. }
  856. /**
  857. * auto_remove_settings - remove driver specific settings
  858. * @drive: drive
  859. *
  860. * Automatically remove all the driver specific settings for this
  861. * drive. This function may sleep and must not be called from IRQ
  862. * context. The caller must hold ide_setting_sem.
  863. */
  864. static void auto_remove_settings (ide_drive_t *drive)
  865. {
  866. ide_settings_t *setting;
  867. repeat:
  868. setting = drive->settings;
  869. while (setting) {
  870. if (setting->auto_remove) {
  871. __ide_remove_setting(drive, setting->name);
  872. goto repeat;
  873. }
  874. setting = setting->next;
  875. }
  876. }
  877. /**
  878. * ide_read_setting - read an IDE setting
  879. * @drive: drive to read from
  880. * @setting: drive setting
  881. *
  882. * Read a drive setting and return the value. The caller
  883. * must hold the ide_setting_sem when making this call.
  884. *
  885. * BUGS: the data return and error are the same return value
  886. * so an error -EINVAL and true return of the same value cannot
  887. * be told apart
  888. */
  889. int ide_read_setting (ide_drive_t *drive, ide_settings_t *setting)
  890. {
  891. int val = -EINVAL;
  892. unsigned long flags;
  893. if ((setting->rw & SETTING_READ)) {
  894. spin_lock_irqsave(&ide_lock, flags);
  895. switch(setting->data_type) {
  896. case TYPE_BYTE:
  897. val = *((u8 *) setting->data);
  898. break;
  899. case TYPE_SHORT:
  900. val = *((u16 *) setting->data);
  901. break;
  902. case TYPE_INT:
  903. case TYPE_INTA:
  904. val = *((u32 *) setting->data);
  905. break;
  906. }
  907. spin_unlock_irqrestore(&ide_lock, flags);
  908. }
  909. return val;
  910. }
  911. /**
  912. * ide_spin_wait_hwgroup - wait for group
  913. * @drive: drive in the group
  914. *
  915. * Wait for an IDE device group to go non busy and then return
  916. * holding the ide_lock which guards the hwgroup->busy status
  917. * and right to use it.
  918. */
  919. int ide_spin_wait_hwgroup (ide_drive_t *drive)
  920. {
  921. ide_hwgroup_t *hwgroup = HWGROUP(drive);
  922. unsigned long timeout = jiffies + (3 * HZ);
  923. spin_lock_irq(&ide_lock);
  924. while (hwgroup->busy) {
  925. unsigned long lflags;
  926. spin_unlock_irq(&ide_lock);
  927. local_irq_set(lflags);
  928. if (time_after(jiffies, timeout)) {
  929. local_irq_restore(lflags);
  930. printk(KERN_ERR "%s: channel busy\n", drive->name);
  931. return -EBUSY;
  932. }
  933. local_irq_restore(lflags);
  934. spin_lock_irq(&ide_lock);
  935. }
  936. return 0;
  937. }
  938. EXPORT_SYMBOL(ide_spin_wait_hwgroup);
  939. /**
  940. * ide_write_setting - read an IDE setting
  941. * @drive: drive to read from
  942. * @setting: drive setting
  943. * @val: value
  944. *
  945. * Write a drive setting if it is possible. The caller
  946. * must hold the ide_setting_sem when making this call.
  947. *
  948. * BUGS: the data return and error are the same return value
  949. * so an error -EINVAL and true return of the same value cannot
  950. * be told apart
  951. *
  952. * FIXME: This should be changed to enqueue a special request
  953. * to the driver to change settings, and then wait on a sema for completion.
  954. * The current scheme of polling is kludgy, though safe enough.
  955. */
  956. int ide_write_setting (ide_drive_t *drive, ide_settings_t *setting, int val)
  957. {
  958. int i;
  959. u32 *p;
  960. if (!capable(CAP_SYS_ADMIN))
  961. return -EACCES;
  962. if (!(setting->rw & SETTING_WRITE))
  963. return -EPERM;
  964. if (val < setting->min || val > setting->max)
  965. return -EINVAL;
  966. if (setting->set)
  967. return setting->set(drive, val);
  968. if (ide_spin_wait_hwgroup(drive))
  969. return -EBUSY;
  970. switch (setting->data_type) {
  971. case TYPE_BYTE:
  972. *((u8 *) setting->data) = val;
  973. break;
  974. case TYPE_SHORT:
  975. *((u16 *) setting->data) = val;
  976. break;
  977. case TYPE_INT:
  978. *((u32 *) setting->data) = val;
  979. break;
  980. case TYPE_INTA:
  981. p = (u32 *) setting->data;
  982. for (i = 0; i < 1 << PARTN_BITS; i++, p++)
  983. *p = val;
  984. break;
  985. }
  986. spin_unlock_irq(&ide_lock);
  987. return 0;
  988. }
  989. static int set_io_32bit(ide_drive_t *drive, int arg)
  990. {
  991. drive->io_32bit = arg;
  992. #ifdef CONFIG_BLK_DEV_DTC2278
  993. if (HWIF(drive)->chipset == ide_dtc2278)
  994. HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
  995. #endif /* CONFIG_BLK_DEV_DTC2278 */
  996. return 0;
  997. }
  998. static int set_using_dma (ide_drive_t *drive, int arg)
  999. {
  1000. #ifdef CONFIG_BLK_DEV_IDEDMA
  1001. if (!drive->id || !(drive->id->capability & 1))
  1002. return -EPERM;
  1003. if (HWIF(drive)->ide_dma_check == NULL)
  1004. return -EPERM;
  1005. if (arg) {
  1006. if (HWIF(drive)->ide_dma_check(drive)) return -EIO;
  1007. if (HWIF(drive)->ide_dma_on(drive)) return -EIO;
  1008. } else {
  1009. if (__ide_dma_off(drive))
  1010. return -EIO;
  1011. }
  1012. return 0;
  1013. #else
  1014. return -EPERM;
  1015. #endif
  1016. }
  1017. static int set_pio_mode (ide_drive_t *drive, int arg)
  1018. {
  1019. struct request rq;
  1020. if (!HWIF(drive)->tuneproc)
  1021. return -ENOSYS;
  1022. if (drive->special.b.set_tune)
  1023. return -EBUSY;
  1024. ide_init_drive_cmd(&rq);
  1025. drive->tune_req = (u8) arg;
  1026. drive->special.b.set_tune = 1;
  1027. (void) ide_do_drive_cmd(drive, &rq, ide_wait);
  1028. return 0;
  1029. }
  1030. static int set_xfer_rate (ide_drive_t *drive, int arg)
  1031. {
  1032. int err = ide_wait_cmd(drive,
  1033. WIN_SETFEATURES, (u8) arg,
  1034. SETFEATURES_XFER, 0, NULL);
  1035. if (!err && arg) {
  1036. ide_set_xfer_rate(drive, (u8) arg);
  1037. ide_driveid_update(drive);
  1038. }
  1039. return err;
  1040. }
  1041. /**
  1042. * ide_add_generic_settings - generic ide settings
  1043. * @drive: drive being configured
  1044. *
  1045. * Add the generic parts of the system settings to the /proc files and
  1046. * ioctls for this IDE device. The caller must not be holding the
  1047. * ide_setting_sem.
  1048. */
  1049. void ide_add_generic_settings (ide_drive_t *drive)
  1050. {
  1051. /*
  1052. * drive setting name read/write access read ioctl write ioctl data type min max mul_factor div_factor data pointer set function
  1053. */
  1054. __ide_add_setting(drive, "io_32bit", drive->no_io_32bit ? SETTING_READ : SETTING_RW, HDIO_GET_32BIT, HDIO_SET_32BIT, TYPE_BYTE, 0, 1 + (SUPPORT_VLB_SYNC << 1), 1, 1, &drive->io_32bit, set_io_32bit, 0);
  1055. __ide_add_setting(drive, "keepsettings", SETTING_RW, HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, TYPE_BYTE, 0, 1, 1, 1, &drive->keep_settings, NULL, 0);
  1056. __ide_add_setting(drive, "nice1", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->nice1, NULL, 0);
  1057. __ide_add_setting(drive, "pio_mode", SETTING_WRITE, -1, HDIO_SET_PIO_MODE, TYPE_BYTE, 0, 255, 1, 1, NULL, set_pio_mode, 0);
  1058. __ide_add_setting(drive, "unmaskirq", drive->no_unmask ? SETTING_READ : SETTING_RW, HDIO_GET_UNMASKINTR, HDIO_SET_UNMASKINTR, TYPE_BYTE, 0, 1, 1, 1, &drive->unmask, NULL, 0);
  1059. __ide_add_setting(drive, "using_dma", SETTING_RW, HDIO_GET_DMA, HDIO_SET_DMA, TYPE_BYTE, 0, 1, 1, 1, &drive->using_dma, set_using_dma, 0);
  1060. __ide_add_setting(drive, "init_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->init_speed, NULL, 0);
  1061. __ide_add_setting(drive, "current_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->current_speed, set_xfer_rate, 0);
  1062. __ide_add_setting(drive, "number", SETTING_RW, -1, -1, TYPE_BYTE, 0, 3, 1, 1, &drive->dn, NULL, 0);
  1063. }
  1064. /**
  1065. * system_bus_clock - clock guess
  1066. *
  1067. * External version of the bus clock guess used by very old IDE drivers
  1068. * for things like VLB timings. Should not be used.
  1069. */
  1070. int system_bus_clock (void)
  1071. {
  1072. return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
  1073. }
  1074. EXPORT_SYMBOL(system_bus_clock);
  1075. static int generic_ide_suspend(struct device *dev, pm_message_t state)
  1076. {
  1077. ide_drive_t *drive = dev->driver_data;
  1078. struct request rq;
  1079. struct request_pm_state rqpm;
  1080. ide_task_t args;
  1081. memset(&rq, 0, sizeof(rq));
  1082. memset(&rqpm, 0, sizeof(rqpm));
  1083. memset(&args, 0, sizeof(args));
  1084. rq.flags = REQ_PM_SUSPEND;
  1085. rq.special = &args;
  1086. rq.pm = &rqpm;
  1087. rqpm.pm_step = ide_pm_state_start_suspend;
  1088. rqpm.pm_state = state.event;
  1089. return ide_do_drive_cmd(drive, &rq, ide_wait);
  1090. }
  1091. static int generic_ide_resume(struct device *dev)
  1092. {
  1093. ide_drive_t *drive = dev->driver_data;
  1094. struct request rq;
  1095. struct request_pm_state rqpm;
  1096. ide_task_t args;
  1097. memset(&rq, 0, sizeof(rq));
  1098. memset(&rqpm, 0, sizeof(rqpm));
  1099. memset(&args, 0, sizeof(args));
  1100. rq.flags = REQ_PM_RESUME;
  1101. rq.special = &args;
  1102. rq.pm = &rqpm;
  1103. rqpm.pm_step = ide_pm_state_start_resume;
  1104. rqpm.pm_state = PM_EVENT_ON;
  1105. return ide_do_drive_cmd(drive, &rq, ide_head_wait);
  1106. }
  1107. int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
  1108. unsigned int cmd, unsigned long arg)
  1109. {
  1110. ide_settings_t *setting;
  1111. ide_driver_t *drv;
  1112. int err = 0;
  1113. void __user *p = (void __user *)arg;
  1114. down(&ide_setting_sem);
  1115. if ((setting = ide_find_setting_by_ioctl(drive, cmd)) != NULL) {
  1116. if (cmd == setting->read_ioctl) {
  1117. err = ide_read_setting(drive, setting);
  1118. up(&ide_setting_sem);
  1119. return err >= 0 ? put_user(err, (long __user *)arg) : err;
  1120. } else {
  1121. if (bdev != bdev->bd_contains)
  1122. err = -EINVAL;
  1123. else
  1124. err = ide_write_setting(drive, setting, arg);
  1125. up(&ide_setting_sem);
  1126. return err;
  1127. }
  1128. }
  1129. up(&ide_setting_sem);
  1130. switch (cmd) {
  1131. case HDIO_GETGEO:
  1132. {
  1133. struct hd_geometry geom;
  1134. if (!p || (drive->media != ide_disk && drive->media != ide_floppy)) return -EINVAL;
  1135. geom.heads = drive->bios_head;
  1136. geom.sectors = drive->bios_sect;
  1137. geom.cylinders = (u16)drive->bios_cyl; /* truncate */
  1138. geom.start = get_start_sect(bdev);
  1139. if (copy_to_user(p, &geom, sizeof(struct hd_geometry)))
  1140. return -EFAULT;
  1141. return 0;
  1142. }
  1143. case HDIO_OBSOLETE_IDENTITY:
  1144. case HDIO_GET_IDENTITY:
  1145. if (bdev != bdev->bd_contains)
  1146. return -EINVAL;
  1147. if (drive->id_read == 0)
  1148. return -ENOMSG;
  1149. if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
  1150. return -EFAULT;
  1151. return 0;
  1152. case HDIO_GET_NICE:
  1153. return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
  1154. drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
  1155. drive->nice0 << IDE_NICE_0 |
  1156. drive->nice1 << IDE_NICE_1 |
  1157. drive->nice2 << IDE_NICE_2,
  1158. (long __user *) arg);
  1159. #ifdef CONFIG_IDE_TASK_IOCTL
  1160. case HDIO_DRIVE_TASKFILE:
  1161. if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
  1162. return -EACCES;
  1163. switch(drive->media) {
  1164. case ide_disk:
  1165. return ide_taskfile_ioctl(drive, cmd, arg);
  1166. default:
  1167. return -ENOMSG;
  1168. }
  1169. #endif /* CONFIG_IDE_TASK_IOCTL */
  1170. case HDIO_DRIVE_CMD:
  1171. if (!capable(CAP_SYS_RAWIO))
  1172. return -EACCES;
  1173. return ide_cmd_ioctl(drive, cmd, arg);
  1174. case HDIO_DRIVE_TASK:
  1175. if (!capable(CAP_SYS_RAWIO))
  1176. return -EACCES;
  1177. return ide_task_ioctl(drive, cmd, arg);
  1178. case HDIO_SCAN_HWIF:
  1179. {
  1180. hw_regs_t hw;
  1181. int args[3];
  1182. if (!capable(CAP_SYS_RAWIO)) return -EACCES;
  1183. if (copy_from_user(args, p, 3 * sizeof(int)))
  1184. return -EFAULT;
  1185. memset(&hw, 0, sizeof(hw));
  1186. ide_init_hwif_ports(&hw, (unsigned long) args[0],
  1187. (unsigned long) args[1], NULL);
  1188. hw.irq = args[2];
  1189. if (ide_register_hw(&hw, NULL) == -1)
  1190. return -EIO;
  1191. return 0;
  1192. }
  1193. case HDIO_UNREGISTER_HWIF:
  1194. if (!capable(CAP_SYS_RAWIO)) return -EACCES;
  1195. /* (arg > MAX_HWIFS) checked in function */
  1196. ide_unregister(arg);
  1197. return 0;
  1198. case HDIO_SET_NICE:
  1199. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  1200. if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
  1201. return -EPERM;
  1202. drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
  1203. drv = *(ide_driver_t **)bdev->bd_disk->private_data;
  1204. if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
  1205. drive->dsc_overlap = 0;
  1206. return -EPERM;
  1207. }
  1208. drive->nice1 = (arg >> IDE_NICE_1) & 1;
  1209. return 0;
  1210. case HDIO_DRIVE_RESET:
  1211. {
  1212. unsigned long flags;
  1213. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  1214. /*
  1215. * Abort the current command on the
  1216. * group if there is one, taking
  1217. * care not to allow anything else
  1218. * to be queued and to die on the
  1219. * spot if we miss one somehow
  1220. */
  1221. spin_lock_irqsave(&ide_lock, flags);
  1222. ide_abort(drive, "drive reset");
  1223. if(HWGROUP(drive)->handler)
  1224. BUG();
  1225. /* Ensure nothing gets queued after we
  1226. drop the lock. Reset will clear the busy */
  1227. HWGROUP(drive)->busy = 1;
  1228. spin_unlock_irqrestore(&ide_lock, flags);
  1229. (void) ide_do_reset(drive);
  1230. return 0;
  1231. }
  1232. case CDROMEJECT:
  1233. case CDROMCLOSETRAY:
  1234. return scsi_cmd_ioctl(file, bdev->bd_disk, cmd, p);
  1235. case HDIO_GET_BUSSTATE:
  1236. if (!capable(CAP_SYS_ADMIN))
  1237. return -EACCES;
  1238. if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
  1239. return -EFAULT;
  1240. return 0;
  1241. case HDIO_SET_BUSSTATE:
  1242. if (!capable(CAP_SYS_ADMIN))
  1243. return -EACCES;
  1244. if (HWIF(drive)->busproc)
  1245. return HWIF(drive)->busproc(drive, (int)arg);
  1246. return -EOPNOTSUPP;
  1247. default:
  1248. return -EINVAL;
  1249. }
  1250. }
  1251. EXPORT_SYMBOL(generic_ide_ioctl);
  1252. /*
  1253. * stridx() returns the offset of c within s,
  1254. * or -1 if c is '\0' or not found within s.
  1255. */
  1256. static int __init stridx (const char *s, char c)
  1257. {
  1258. char *i = strchr(s, c);
  1259. return (i && c) ? i - s : -1;
  1260. }
  1261. /*
  1262. * match_parm() does parsing for ide_setup():
  1263. *
  1264. * 1. the first char of s must be '='.
  1265. * 2. if the remainder matches one of the supplied keywords,
  1266. * the index (1 based) of the keyword is negated and returned.
  1267. * 3. if the remainder is a series of no more than max_vals numbers
  1268. * separated by commas, the numbers are saved in vals[] and a
  1269. * count of how many were saved is returned. Base10 is assumed,
  1270. * and base16 is allowed when prefixed with "0x".
  1271. * 4. otherwise, zero is returned.
  1272. */
  1273. static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
  1274. {
  1275. static const char *decimal = "0123456789";
  1276. static const char *hex = "0123456789abcdef";
  1277. int i, n;
  1278. if (*s++ == '=') {
  1279. /*
  1280. * Try matching against the supplied keywords,
  1281. * and return -(index+1) if we match one
  1282. */
  1283. if (keywords != NULL) {
  1284. for (i = 0; *keywords != NULL; ++i) {
  1285. if (!strcmp(s, *keywords++))
  1286. return -(i+1);
  1287. }
  1288. }
  1289. /*
  1290. * Look for a series of no more than "max_vals"
  1291. * numeric values separated by commas, in base10,
  1292. * or base16 when prefixed with "0x".
  1293. * Return a count of how many were found.
  1294. */
  1295. for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
  1296. vals[n] = i;
  1297. while ((i = stridx(decimal, *++s)) >= 0)
  1298. vals[n] = (vals[n] * 10) + i;
  1299. if (*s == 'x' && !vals[n]) {
  1300. while ((i = stridx(hex, *++s)) >= 0)
  1301. vals[n] = (vals[n] * 0x10) + i;
  1302. }
  1303. if (++n == max_vals)
  1304. break;
  1305. if (*s == ',' || *s == ';')
  1306. ++s;
  1307. }
  1308. if (!*s)
  1309. return n;
  1310. }
  1311. return 0; /* zero = nothing matched */
  1312. }
  1313. #ifdef CONFIG_BLK_DEV_ALI14XX
  1314. static int __initdata probe_ali14xx;
  1315. extern int ali14xx_init(void);
  1316. #endif
  1317. #ifdef CONFIG_BLK_DEV_UMC8672
  1318. static int __initdata probe_umc8672;
  1319. extern int umc8672_init(void);
  1320. #endif
  1321. #ifdef CONFIG_BLK_DEV_DTC2278
  1322. static int __initdata probe_dtc2278;
  1323. extern int dtc2278_init(void);
  1324. #endif
  1325. #ifdef CONFIG_BLK_DEV_HT6560B
  1326. static int __initdata probe_ht6560b;
  1327. extern int ht6560b_init(void);
  1328. #endif
  1329. #ifdef CONFIG_BLK_DEV_QD65XX
  1330. static int __initdata probe_qd65xx;
  1331. extern int qd65xx_init(void);
  1332. #endif
  1333. static int __initdata is_chipset_set[MAX_HWIFS];
  1334. /*
  1335. * ide_setup() gets called VERY EARLY during initialization,
  1336. * to handle kernel "command line" strings beginning with "hdx=" or "ide".
  1337. *
  1338. * Remember to update Documentation/ide.txt if you change something here.
  1339. */
  1340. static int __init ide_setup(char *s)
  1341. {
  1342. int i, vals[3];
  1343. ide_hwif_t *hwif;
  1344. ide_drive_t *drive;
  1345. unsigned int hw, unit;
  1346. const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
  1347. const char max_hwif = '0' + (MAX_HWIFS - 1);
  1348. if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
  1349. return 0; /* driver and not us */
  1350. if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
  1351. return 0;
  1352. printk(KERN_INFO "ide_setup: %s", s);
  1353. init_ide_data ();
  1354. #ifdef CONFIG_BLK_DEV_IDEDOUBLER
  1355. if (!strcmp(s, "ide=doubler")) {
  1356. extern int ide_doubler;
  1357. printk(" : Enabled support for IDE doublers\n");
  1358. ide_doubler = 1;
  1359. return 1;
  1360. }
  1361. #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
  1362. if (!strcmp(s, "ide=nodma")) {
  1363. printk(" : Prevented DMA\n");
  1364. noautodma = 1;
  1365. return 1;
  1366. }
  1367. #ifdef CONFIG_BLK_DEV_IDEPCI
  1368. if (!strcmp(s, "ide=reverse")) {
  1369. ide_scan_direction = 1;
  1370. printk(" : Enabled support for IDE inverse scan order.\n");
  1371. return 1;
  1372. }
  1373. #endif /* CONFIG_BLK_DEV_IDEPCI */
  1374. /*
  1375. * Look for drive options: "hdx="
  1376. */
  1377. if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
  1378. const char *hd_words[] = {
  1379. "none", "noprobe", "nowerr", "cdrom", "serialize",
  1380. "autotune", "noautotune", "minus8", "swapdata", "bswap",
  1381. "minus11", "remap", "remap63", "scsi", NULL };
  1382. unit = s[2] - 'a';
  1383. hw = unit / MAX_DRIVES;
  1384. unit = unit % MAX_DRIVES;
  1385. hwif = &ide_hwifs[hw];
  1386. drive = &hwif->drives[unit];
  1387. if (strncmp(s + 4, "ide-", 4) == 0) {
  1388. strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
  1389. goto done;
  1390. }
  1391. switch (match_parm(&s[3], hd_words, vals, 3)) {
  1392. case -1: /* "none" */
  1393. case -2: /* "noprobe" */
  1394. drive->noprobe = 1;
  1395. goto done;
  1396. case -3: /* "nowerr" */
  1397. drive->bad_wstat = BAD_R_STAT;
  1398. hwif->noprobe = 0;
  1399. goto done;
  1400. case -4: /* "cdrom" */
  1401. drive->present = 1;
  1402. drive->media = ide_cdrom;
  1403. /* an ATAPI device ignores DRDY */
  1404. drive->ready_stat = 0;
  1405. hwif->noprobe = 0;
  1406. goto done;
  1407. case -5: /* "serialize" */
  1408. printk(" -- USE \"ide%d=serialize\" INSTEAD", hw);
  1409. goto do_serialize;
  1410. case -6: /* "autotune" */
  1411. drive->autotune = IDE_TUNE_AUTO;
  1412. goto obsolete_option;
  1413. case -7: /* "noautotune" */
  1414. drive->autotune = IDE_TUNE_NOAUTO;
  1415. goto obsolete_option;
  1416. case -9: /* "swapdata" */
  1417. case -10: /* "bswap" */
  1418. drive->bswap = 1;
  1419. goto done;
  1420. case -12: /* "remap" */
  1421. drive->remap_0_to_1 = 1;
  1422. goto done;
  1423. case -13: /* "remap63" */
  1424. drive->sect0 = 63;
  1425. goto done;
  1426. case -14: /* "scsi" */
  1427. drive->scsi = 1;
  1428. goto done;
  1429. case 3: /* cyl,head,sect */
  1430. drive->media = ide_disk;
  1431. drive->ready_stat = READY_STAT;
  1432. drive->cyl = drive->bios_cyl = vals[0];
  1433. drive->head = drive->bios_head = vals[1];
  1434. drive->sect = drive->bios_sect = vals[2];
  1435. drive->present = 1;
  1436. drive->forced_geom = 1;
  1437. hwif->noprobe = 0;
  1438. goto done;
  1439. default:
  1440. goto bad_option;
  1441. }
  1442. }
  1443. if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
  1444. goto bad_option;
  1445. /*
  1446. * Look for bus speed option: "idebus="
  1447. */
  1448. if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
  1449. if (match_parm(&s[6], NULL, vals, 1) != 1)
  1450. goto bad_option;
  1451. if (vals[0] >= 20 && vals[0] <= 66) {
  1452. idebus_parameter = vals[0];
  1453. } else
  1454. printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
  1455. goto done;
  1456. }
  1457. /*
  1458. * Look for interface options: "idex="
  1459. */
  1460. if (s[3] >= '0' && s[3] <= max_hwif) {
  1461. /*
  1462. * Be VERY CAREFUL changing this: note hardcoded indexes below
  1463. * (-8, -9, -10) are reserved to ease the hardcoding.
  1464. */
  1465. static const char *ide_words[] = {
  1466. "noprobe", "serialize", "autotune", "noautotune",
  1467. "reset", "dma", "ata66", "minus8", "minus9",
  1468. "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
  1469. "dtc2278", "umc8672", "ali14xx", NULL };
  1470. hw = s[3] - '0';
  1471. hwif = &ide_hwifs[hw];
  1472. i = match_parm(&s[4], ide_words, vals, 3);
  1473. /*
  1474. * Cryptic check to ensure chipset not already set for hwif.
  1475. * Note: we can't depend on hwif->chipset here.
  1476. */
  1477. if ((i >= -18 && i <= -11) || (i > 0 && i <= 3)) {
  1478. /* chipset already specified */
  1479. if (is_chipset_set[hw])
  1480. goto bad_option;
  1481. if (i > -18 && i <= -11) {
  1482. /* these drivers are for "ide0=" only */
  1483. if (hw != 0)
  1484. goto bad_hwif;
  1485. /* chipset already specified for 2nd port */
  1486. if (is_chipset_set[hw+1])
  1487. goto bad_option;
  1488. }
  1489. is_chipset_set[hw] = 1;
  1490. printk("\n");
  1491. }
  1492. switch (i) {
  1493. #ifdef CONFIG_BLK_DEV_ALI14XX
  1494. case -17: /* "ali14xx" */
  1495. probe_ali14xx = 1;
  1496. goto done;
  1497. #endif
  1498. #ifdef CONFIG_BLK_DEV_UMC8672
  1499. case -16: /* "umc8672" */
  1500. probe_umc8672 = 1;
  1501. goto done;
  1502. #endif
  1503. #ifdef CONFIG_BLK_DEV_DTC2278
  1504. case -15: /* "dtc2278" */
  1505. probe_dtc2278 = 1;
  1506. goto done;
  1507. #endif
  1508. #ifdef CONFIG_BLK_DEV_CMD640
  1509. case -14: /* "cmd640_vlb" */
  1510. {
  1511. extern int cmd640_vlb; /* flag for cmd640.c */
  1512. cmd640_vlb = 1;
  1513. goto done;
  1514. }
  1515. #endif
  1516. #ifdef CONFIG_BLK_DEV_HT6560B
  1517. case -13: /* "ht6560b" */
  1518. probe_ht6560b = 1;
  1519. goto done;
  1520. #endif
  1521. #ifdef CONFIG_BLK_DEV_QD65XX
  1522. case -12: /* "qd65xx" */
  1523. probe_qd65xx = 1;
  1524. goto done;
  1525. #endif
  1526. #ifdef CONFIG_BLK_DEV_4DRIVES
  1527. case -11: /* "four" drives on one set of ports */
  1528. {
  1529. ide_hwif_t *mate = &ide_hwifs[hw^1];
  1530. mate->drives[0].select.all ^= 0x20;
  1531. mate->drives[1].select.all ^= 0x20;
  1532. hwif->chipset = mate->chipset = ide_4drives;
  1533. mate->irq = hwif->irq;
  1534. memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
  1535. goto do_serialize;
  1536. }
  1537. #endif /* CONFIG_BLK_DEV_4DRIVES */
  1538. case -10: /* minus10 */
  1539. case -9: /* minus9 */
  1540. case -8: /* minus8 */
  1541. goto bad_option;
  1542. case -7: /* ata66 */
  1543. #ifdef CONFIG_BLK_DEV_IDEPCI
  1544. hwif->udma_four = 1;
  1545. goto obsolete_option;
  1546. #else
  1547. goto bad_hwif;
  1548. #endif
  1549. case -6: /* dma */
  1550. hwif->autodma = 1;
  1551. goto obsolete_option;
  1552. case -5: /* "reset" */
  1553. hwif->reset = 1;
  1554. goto obsolete_option;
  1555. case -4: /* "noautotune" */
  1556. hwif->drives[0].autotune = IDE_TUNE_NOAUTO;
  1557. hwif->drives[1].autotune = IDE_TUNE_NOAUTO;
  1558. goto obsolete_option;
  1559. case -3: /* "autotune" */
  1560. hwif->drives[0].autotune = IDE_TUNE_AUTO;
  1561. hwif->drives[1].autotune = IDE_TUNE_AUTO;
  1562. goto obsolete_option;
  1563. case -2: /* "serialize" */
  1564. do_serialize:
  1565. hwif->mate = &ide_hwifs[hw^1];
  1566. hwif->mate->mate = hwif;
  1567. hwif->serialized = hwif->mate->serialized = 1;
  1568. goto obsolete_option;
  1569. case -1: /* "noprobe" */
  1570. hwif->noprobe = 1;
  1571. goto done;
  1572. case 1: /* base */
  1573. vals[1] = vals[0] + 0x206; /* default ctl */
  1574. case 2: /* base,ctl */
  1575. vals[2] = 0; /* default irq = probe for it */
  1576. case 3: /* base,ctl,irq */
  1577. hwif->hw.irq = vals[2];
  1578. ide_init_hwif_ports(&hwif->hw, (unsigned long) vals[0], (unsigned long) vals[1], &hwif->irq);
  1579. memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
  1580. hwif->irq = vals[2];
  1581. hwif->noprobe = 0;
  1582. hwif->chipset = ide_forced;
  1583. goto obsolete_option;
  1584. case 0: goto bad_option;
  1585. default:
  1586. printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
  1587. return 1;
  1588. }
  1589. }
  1590. bad_option:
  1591. printk(" -- BAD OPTION\n");
  1592. return 1;
  1593. obsolete_option:
  1594. printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
  1595. return 1;
  1596. bad_hwif:
  1597. printk("-- NOT SUPPORTED ON ide%d", hw);
  1598. done:
  1599. printk("\n");
  1600. return 1;
  1601. }
  1602. extern void pnpide_init(void);
  1603. extern void h8300_ide_init(void);
  1604. /*
  1605. * probe_for_hwifs() finds/initializes "known" IDE interfaces
  1606. */
  1607. static void __init probe_for_hwifs (void)
  1608. {
  1609. #ifdef CONFIG_BLK_DEV_IDEPCI
  1610. ide_scan_pcibus(ide_scan_direction);
  1611. #endif /* CONFIG_BLK_DEV_IDEPCI */
  1612. #ifdef CONFIG_ETRAX_IDE
  1613. {
  1614. extern void init_e100_ide(void);
  1615. init_e100_ide();
  1616. }
  1617. #endif /* CONFIG_ETRAX_IDE */
  1618. #ifdef CONFIG_BLK_DEV_CMD640
  1619. {
  1620. extern void ide_probe_for_cmd640x(void);
  1621. ide_probe_for_cmd640x();
  1622. }
  1623. #endif /* CONFIG_BLK_DEV_CMD640 */
  1624. #ifdef CONFIG_BLK_DEV_IDE_PMAC
  1625. {
  1626. extern void pmac_ide_probe(void);
  1627. pmac_ide_probe();
  1628. }
  1629. #endif /* CONFIG_BLK_DEV_IDE_PMAC */
  1630. #ifdef CONFIG_BLK_DEV_GAYLE
  1631. {
  1632. extern void gayle_init(void);
  1633. gayle_init();
  1634. }
  1635. #endif /* CONFIG_BLK_DEV_GAYLE */
  1636. #ifdef CONFIG_BLK_DEV_FALCON_IDE
  1637. {
  1638. extern void falconide_init(void);
  1639. falconide_init();
  1640. }
  1641. #endif /* CONFIG_BLK_DEV_FALCON_IDE */
  1642. #ifdef CONFIG_BLK_DEV_MAC_IDE
  1643. {
  1644. extern void macide_init(void);
  1645. macide_init();
  1646. }
  1647. #endif /* CONFIG_BLK_DEV_MAC_IDE */
  1648. #ifdef CONFIG_BLK_DEV_Q40IDE
  1649. {
  1650. extern void q40ide_init(void);
  1651. q40ide_init();
  1652. }
  1653. #endif /* CONFIG_BLK_DEV_Q40IDE */
  1654. #ifdef CONFIG_BLK_DEV_BUDDHA
  1655. {
  1656. extern void buddha_init(void);
  1657. buddha_init();
  1658. }
  1659. #endif /* CONFIG_BLK_DEV_BUDDHA */
  1660. #ifdef CONFIG_BLK_DEV_IDEPNP
  1661. pnpide_init();
  1662. #endif
  1663. #ifdef CONFIG_H8300
  1664. h8300_ide_init();
  1665. #endif
  1666. }
  1667. void ide_register_subdriver(ide_drive_t *drive, ide_driver_t *driver)
  1668. {
  1669. #ifdef CONFIG_PROC_FS
  1670. ide_add_proc_entries(drive->proc, driver->proc, drive);
  1671. #endif
  1672. }
  1673. EXPORT_SYMBOL(ide_register_subdriver);
  1674. /**
  1675. * ide_unregister_subdriver - disconnect drive from driver
  1676. * @drive: drive to unplug
  1677. * @driver: driver
  1678. *
  1679. * Disconnect a drive from the driver it was attached to and then
  1680. * clean up the various proc files and other objects attached to it.
  1681. *
  1682. * Takes ide_setting_sem and ide_lock.
  1683. * Caller must hold none of the locks.
  1684. */
  1685. void ide_unregister_subdriver(ide_drive_t *drive, ide_driver_t *driver)
  1686. {
  1687. unsigned long flags;
  1688. down(&ide_setting_sem);
  1689. spin_lock_irqsave(&ide_lock, flags);
  1690. #ifdef CONFIG_PROC_FS
  1691. ide_remove_proc_entries(drive->proc, driver->proc);
  1692. #endif
  1693. auto_remove_settings(drive);
  1694. spin_unlock_irqrestore(&ide_lock, flags);
  1695. up(&ide_setting_sem);
  1696. }
  1697. EXPORT_SYMBOL(ide_unregister_subdriver);
  1698. /*
  1699. * Probe module
  1700. */
  1701. EXPORT_SYMBOL(ide_lock);
  1702. static int ide_bus_match(struct device *dev, struct device_driver *drv)
  1703. {
  1704. return 1;
  1705. }
  1706. struct bus_type ide_bus_type = {
  1707. .name = "ide",
  1708. .match = ide_bus_match,
  1709. .suspend = generic_ide_suspend,
  1710. .resume = generic_ide_resume,
  1711. };
  1712. EXPORT_SYMBOL_GPL(ide_bus_type);
  1713. /*
  1714. * This is gets invoked once during initialization, to set *everything* up
  1715. */
  1716. static int __init ide_init(void)
  1717. {
  1718. printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
  1719. devfs_mk_dir("ide");
  1720. system_bus_speed = ide_system_bus_speed();
  1721. bus_register(&ide_bus_type);
  1722. init_ide_data();
  1723. #ifdef CONFIG_PROC_FS
  1724. proc_ide_root = proc_mkdir("ide", NULL);
  1725. #endif
  1726. #ifdef CONFIG_BLK_DEV_ALI14XX
  1727. if (probe_ali14xx)
  1728. (void)ali14xx_init();
  1729. #endif
  1730. #ifdef CONFIG_BLK_DEV_UMC8672
  1731. if (probe_umc8672)
  1732. (void)umc8672_init();
  1733. #endif
  1734. #ifdef CONFIG_BLK_DEV_DTC2278
  1735. if (probe_dtc2278)
  1736. (void)dtc2278_init();
  1737. #endif
  1738. #ifdef CONFIG_BLK_DEV_HT6560B
  1739. if (probe_ht6560b)
  1740. (void)ht6560b_init();
  1741. #endif
  1742. #ifdef CONFIG_BLK_DEV_QD65XX
  1743. if (probe_qd65xx)
  1744. (void)qd65xx_init();
  1745. #endif
  1746. initializing = 1;
  1747. /* Probe for special PCI and other "known" interface chipsets. */
  1748. probe_for_hwifs();
  1749. initializing = 0;
  1750. #ifdef CONFIG_PROC_FS
  1751. proc_ide_create();
  1752. #endif
  1753. return 0;
  1754. }
  1755. #ifdef MODULE
  1756. static char *options = NULL;
  1757. module_param(options, charp, 0);
  1758. MODULE_LICENSE("GPL");
  1759. static void __init parse_options (char *line)
  1760. {
  1761. char *next = line;
  1762. if (line == NULL || !*line)
  1763. return;
  1764. while ((line = next) != NULL) {
  1765. if ((next = strchr(line,' ')) != NULL)
  1766. *next++ = 0;
  1767. if (!ide_setup(line))
  1768. printk (KERN_INFO "Unknown option '%s'\n", line);
  1769. }
  1770. }
  1771. int init_module (void)
  1772. {
  1773. parse_options(options);
  1774. return ide_init();
  1775. }
  1776. void cleanup_module (void)
  1777. {
  1778. int index;
  1779. for (index = 0; index < MAX_HWIFS; ++index)
  1780. ide_unregister(index);
  1781. #ifdef CONFIG_PROC_FS
  1782. proc_ide_destroy();
  1783. #endif
  1784. devfs_remove("ide");
  1785. bus_unregister(&ide_bus_type);
  1786. }
  1787. #else /* !MODULE */
  1788. __setup("", ide_setup);
  1789. module_init(ide_init);
  1790. #endif /* MODULE */