ide.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889
  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. #define _IDE_C /* Tell ide.h it's really us */
  127. #include <linux/module.h>
  128. #include <linux/types.h>
  129. #include <linux/string.h>
  130. #include <linux/kernel.h>
  131. #include <linux/timer.h>
  132. #include <linux/mm.h>
  133. #include <linux/interrupt.h>
  134. #include <linux/major.h>
  135. #include <linux/errno.h>
  136. #include <linux/genhd.h>
  137. #include <linux/blkpg.h>
  138. #include <linux/slab.h>
  139. #include <linux/init.h>
  140. #include <linux/pci.h>
  141. #include <linux/delay.h>
  142. #include <linux/ide.h>
  143. #include <linux/completion.h>
  144. #include <linux/reboot.h>
  145. #include <linux/cdrom.h>
  146. #include <linux/seq_file.h>
  147. #include <linux/device.h>
  148. #include <linux/bitops.h>
  149. #include <asm/byteorder.h>
  150. #include <asm/irq.h>
  151. #include <asm/uaccess.h>
  152. #include <asm/io.h>
  153. /* default maximum number of failures */
  154. #define IDE_DEFAULT_MAX_FAILURES 1
  155. static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
  156. IDE2_MAJOR, IDE3_MAJOR,
  157. IDE4_MAJOR, IDE5_MAJOR,
  158. IDE6_MAJOR, IDE7_MAJOR,
  159. IDE8_MAJOR, IDE9_MAJOR };
  160. static int idebus_parameter; /* holds the "idebus=" parameter */
  161. static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */
  162. DEFINE_MUTEX(ide_cfg_mtx);
  163. __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
  164. #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
  165. static int ide_scan_direction; /* THIS was formerly 2.2.x pci=reverse */
  166. #endif
  167. int noautodma = 0;
  168. EXPORT_SYMBOL(noautodma);
  169. #ifdef CONFIG_BLK_DEV_IDEACPI
  170. int ide_noacpi = 0;
  171. int ide_noacpitfs = 1;
  172. int ide_noacpionboot = 1;
  173. #endif
  174. /*
  175. * This is declared extern in ide.h, for access by other IDE modules:
  176. */
  177. ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
  178. EXPORT_SYMBOL(ide_hwifs);
  179. /*
  180. * Do not even *think* about calling this!
  181. */
  182. static void init_hwif_data(ide_hwif_t *hwif, unsigned int index)
  183. {
  184. unsigned int unit;
  185. /* bulk initialize hwif & drive info with zeros */
  186. memset(hwif, 0, sizeof(ide_hwif_t));
  187. /* fill in any non-zero initial values */
  188. hwif->index = index;
  189. hwif->major = ide_hwif_to_major[index];
  190. hwif->name[0] = 'i';
  191. hwif->name[1] = 'd';
  192. hwif->name[2] = 'e';
  193. hwif->name[3] = '0' + index;
  194. hwif->bus_state = BUSSTATE_ON;
  195. hwif->atapi_dma = 0; /* disable all atapi dma */
  196. init_completion(&hwif->gendev_rel_comp);
  197. default_hwif_iops(hwif);
  198. default_hwif_transport(hwif);
  199. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  200. ide_drive_t *drive = &hwif->drives[unit];
  201. drive->media = ide_disk;
  202. drive->select.all = (unit<<4)|0xa0;
  203. drive->hwif = hwif;
  204. drive->ctl = 0x08;
  205. drive->ready_stat = READY_STAT;
  206. drive->bad_wstat = BAD_W_STAT;
  207. drive->special.b.recalibrate = 1;
  208. drive->special.b.set_geometry = 1;
  209. drive->name[0] = 'h';
  210. drive->name[1] = 'd';
  211. drive->name[2] = 'a' + (index * MAX_DRIVES) + unit;
  212. drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
  213. drive->using_dma = 0;
  214. drive->vdma = 0;
  215. INIT_LIST_HEAD(&drive->list);
  216. init_completion(&drive->gendev_rel_comp);
  217. }
  218. }
  219. static void init_hwif_default(ide_hwif_t *hwif, unsigned int index)
  220. {
  221. hw_regs_t hw;
  222. memset(&hw, 0, sizeof(hw_regs_t));
  223. ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
  224. memcpy(&hwif->hw, &hw, sizeof(hw));
  225. memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
  226. hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
  227. #ifdef CONFIG_BLK_DEV_HD
  228. if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)
  229. hwif->noprobe = 1; /* may be overridden by ide_setup() */
  230. #endif
  231. }
  232. extern void ide_arm_init(void);
  233. /*
  234. * init_ide_data() sets reasonable default values into all fields
  235. * of all instances of the hwifs and drives, but only on the first call.
  236. * Subsequent calls have no effect (they don't wipe out anything).
  237. *
  238. * This routine is normally called at driver initialization time,
  239. * but may also be called MUCH earlier during kernel "command-line"
  240. * parameter processing. As such, we cannot depend on any other parts
  241. * of the kernel (such as memory allocation) to be functioning yet.
  242. *
  243. * This is too bad, as otherwise we could dynamically allocate the
  244. * ide_drive_t structs as needed, rather than always consuming memory
  245. * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
  246. *
  247. * FIXME: We should stuff the setup data into __init and copy the
  248. * relevant hwifs/allocate them properly during boot.
  249. */
  250. #define MAGIC_COOKIE 0x12345678
  251. static void __init init_ide_data (void)
  252. {
  253. ide_hwif_t *hwif;
  254. unsigned int index;
  255. static unsigned long magic_cookie = MAGIC_COOKIE;
  256. if (magic_cookie != MAGIC_COOKIE)
  257. return; /* already initialized */
  258. magic_cookie = 0;
  259. /* Initialise all interface structures */
  260. for (index = 0; index < MAX_HWIFS; ++index) {
  261. hwif = &ide_hwifs[index];
  262. init_hwif_data(hwif, index);
  263. init_hwif_default(hwif, index);
  264. #if !defined(CONFIG_PPC32) || !defined(CONFIG_PCI)
  265. hwif->irq = hwif->hw.irq =
  266. ide_init_default_irq(hwif->io_ports[IDE_DATA_OFFSET]);
  267. #endif
  268. }
  269. #ifdef CONFIG_IDE_ARM
  270. ide_arm_init();
  271. #endif
  272. }
  273. /**
  274. * ide_system_bus_speed - guess bus speed
  275. *
  276. * ide_system_bus_speed() returns what we think is the system VESA/PCI
  277. * bus speed (in MHz). This is used for calculating interface PIO timings.
  278. * The default is 40 for known PCI systems, 50 otherwise.
  279. * The "idebus=xx" parameter can be used to override this value.
  280. * The actual value to be used is computed/displayed the first time
  281. * through. Drivers should only use this as a last resort.
  282. *
  283. * Returns a guessed speed in MHz.
  284. */
  285. static int ide_system_bus_speed(void)
  286. {
  287. #ifdef CONFIG_PCI
  288. static struct pci_device_id pci_default[] = {
  289. { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) },
  290. { }
  291. };
  292. #else
  293. #define pci_default 0
  294. #endif /* CONFIG_PCI */
  295. if (!system_bus_speed) {
  296. if (idebus_parameter) {
  297. /* user supplied value */
  298. system_bus_speed = idebus_parameter;
  299. } else if (pci_dev_present(pci_default)) {
  300. /* safe default value for PCI */
  301. system_bus_speed = 33;
  302. } else {
  303. /* safe default value for VESA and PCI */
  304. system_bus_speed = 50;
  305. }
  306. printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
  307. "for PIO modes%s\n", system_bus_speed,
  308. idebus_parameter ? "" : "; override with idebus=xx");
  309. }
  310. return system_bus_speed;
  311. }
  312. static struct resource* hwif_request_region(ide_hwif_t *hwif,
  313. unsigned long addr, int num)
  314. {
  315. struct resource *res = request_region(addr, num, hwif->name);
  316. if (!res)
  317. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
  318. hwif->name, addr, addr+num-1);
  319. return res;
  320. }
  321. /**
  322. * ide_hwif_request_regions - request resources for IDE
  323. * @hwif: interface to use
  324. *
  325. * Requests all the needed resources for an interface.
  326. * Right now core IDE code does this work which is deeply wrong.
  327. * MMIO leaves it to the controller driver,
  328. * PIO will migrate this way over time.
  329. */
  330. int ide_hwif_request_regions(ide_hwif_t *hwif)
  331. {
  332. unsigned long addr;
  333. unsigned int i;
  334. if (hwif->mmio)
  335. return 0;
  336. addr = hwif->io_ports[IDE_CONTROL_OFFSET];
  337. if (addr && !hwif_request_region(hwif, addr, 1))
  338. goto control_region_busy;
  339. hwif->straight8 = 0;
  340. addr = hwif->io_ports[IDE_DATA_OFFSET];
  341. if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) {
  342. if (!hwif_request_region(hwif, addr, 8))
  343. goto data_region_busy;
  344. hwif->straight8 = 1;
  345. return 0;
  346. }
  347. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
  348. addr = hwif->io_ports[i];
  349. if (!hwif_request_region(hwif, addr, 1)) {
  350. while (--i)
  351. release_region(addr, 1);
  352. goto data_region_busy;
  353. }
  354. }
  355. return 0;
  356. data_region_busy:
  357. addr = hwif->io_ports[IDE_CONTROL_OFFSET];
  358. if (addr)
  359. release_region(addr, 1);
  360. control_region_busy:
  361. /* If any errors are return, we drop the hwif interface. */
  362. return -EBUSY;
  363. }
  364. /**
  365. * ide_hwif_release_regions - free IDE resources
  366. *
  367. * Note that we only release the standard ports,
  368. * and do not even try to handle any extra ports
  369. * allocated for weird IDE interface chipsets.
  370. *
  371. * Note also that we don't yet handle mmio resources here. More
  372. * importantly our caller should be doing this so we need to
  373. * restructure this as a helper function for drivers.
  374. */
  375. void ide_hwif_release_regions(ide_hwif_t *hwif)
  376. {
  377. u32 i = 0;
  378. if (hwif->mmio)
  379. return;
  380. if (hwif->io_ports[IDE_CONTROL_OFFSET])
  381. release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
  382. if (hwif->straight8) {
  383. release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
  384. return;
  385. }
  386. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
  387. if (hwif->io_ports[i])
  388. release_region(hwif->io_ports[i], 1);
  389. }
  390. /**
  391. * ide_hwif_restore - restore hwif to template
  392. * @hwif: hwif to update
  393. * @tmp_hwif: template
  394. *
  395. * Restore hwif to a previous state by copying most settings
  396. * from the template.
  397. */
  398. static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
  399. {
  400. hwif->hwgroup = tmp_hwif->hwgroup;
  401. hwif->gendev.parent = tmp_hwif->gendev.parent;
  402. hwif->proc = tmp_hwif->proc;
  403. hwif->major = tmp_hwif->major;
  404. hwif->straight8 = tmp_hwif->straight8;
  405. hwif->bus_state = tmp_hwif->bus_state;
  406. hwif->host_flags = tmp_hwif->host_flags;
  407. hwif->pio_mask = tmp_hwif->pio_mask;
  408. hwif->atapi_dma = tmp_hwif->atapi_dma;
  409. hwif->ultra_mask = tmp_hwif->ultra_mask;
  410. hwif->mwdma_mask = tmp_hwif->mwdma_mask;
  411. hwif->swdma_mask = tmp_hwif->swdma_mask;
  412. hwif->cbl = tmp_hwif->cbl;
  413. hwif->chipset = tmp_hwif->chipset;
  414. hwif->hold = tmp_hwif->hold;
  415. #ifdef CONFIG_BLK_DEV_IDEPCI
  416. hwif->pci_dev = tmp_hwif->pci_dev;
  417. hwif->cds = tmp_hwif->cds;
  418. #endif
  419. hwif->tuneproc = tmp_hwif->tuneproc;
  420. hwif->speedproc = tmp_hwif->speedproc;
  421. hwif->udma_filter = tmp_hwif->udma_filter;
  422. hwif->selectproc = tmp_hwif->selectproc;
  423. hwif->reset_poll = tmp_hwif->reset_poll;
  424. hwif->pre_reset = tmp_hwif->pre_reset;
  425. hwif->resetproc = tmp_hwif->resetproc;
  426. hwif->intrproc = tmp_hwif->intrproc;
  427. hwif->maskproc = tmp_hwif->maskproc;
  428. hwif->quirkproc = tmp_hwif->quirkproc;
  429. hwif->busproc = tmp_hwif->busproc;
  430. hwif->ata_input_data = tmp_hwif->ata_input_data;
  431. hwif->ata_output_data = tmp_hwif->ata_output_data;
  432. hwif->atapi_input_bytes = tmp_hwif->atapi_input_bytes;
  433. hwif->atapi_output_bytes = tmp_hwif->atapi_output_bytes;
  434. hwif->dma_setup = tmp_hwif->dma_setup;
  435. hwif->dma_exec_cmd = tmp_hwif->dma_exec_cmd;
  436. hwif->dma_start = tmp_hwif->dma_start;
  437. hwif->ide_dma_end = tmp_hwif->ide_dma_end;
  438. hwif->ide_dma_check = tmp_hwif->ide_dma_check;
  439. hwif->ide_dma_on = tmp_hwif->ide_dma_on;
  440. hwif->dma_off_quietly = tmp_hwif->dma_off_quietly;
  441. hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq;
  442. hwif->ide_dma_clear_irq = tmp_hwif->ide_dma_clear_irq;
  443. hwif->dma_host_on = tmp_hwif->dma_host_on;
  444. hwif->dma_host_off = tmp_hwif->dma_host_off;
  445. hwif->dma_lost_irq = tmp_hwif->dma_lost_irq;
  446. hwif->dma_timeout = tmp_hwif->dma_timeout;
  447. hwif->OUTB = tmp_hwif->OUTB;
  448. hwif->OUTBSYNC = tmp_hwif->OUTBSYNC;
  449. hwif->OUTW = tmp_hwif->OUTW;
  450. hwif->OUTSW = tmp_hwif->OUTSW;
  451. hwif->OUTSL = tmp_hwif->OUTSL;
  452. hwif->INB = tmp_hwif->INB;
  453. hwif->INW = tmp_hwif->INW;
  454. hwif->INSW = tmp_hwif->INSW;
  455. hwif->INSL = tmp_hwif->INSL;
  456. hwif->sg_max_nents = tmp_hwif->sg_max_nents;
  457. hwif->mmio = tmp_hwif->mmio;
  458. hwif->rqsize = tmp_hwif->rqsize;
  459. hwif->no_lba48 = tmp_hwif->no_lba48;
  460. #ifndef CONFIG_BLK_DEV_IDECS
  461. hwif->irq = tmp_hwif->irq;
  462. #endif
  463. hwif->dma_base = tmp_hwif->dma_base;
  464. hwif->dma_master = tmp_hwif->dma_master;
  465. hwif->dma_command = tmp_hwif->dma_command;
  466. hwif->dma_vendor1 = tmp_hwif->dma_vendor1;
  467. hwif->dma_status = tmp_hwif->dma_status;
  468. hwif->dma_vendor3 = tmp_hwif->dma_vendor3;
  469. hwif->dma_prdtable = tmp_hwif->dma_prdtable;
  470. hwif->config_data = tmp_hwif->config_data;
  471. hwif->select_data = tmp_hwif->select_data;
  472. hwif->extra_base = tmp_hwif->extra_base;
  473. hwif->extra_ports = tmp_hwif->extra_ports;
  474. hwif->autodma = tmp_hwif->autodma;
  475. hwif->hwif_data = tmp_hwif->hwif_data;
  476. }
  477. /**
  478. * ide_unregister - free an IDE interface
  479. * @index: index of interface (will change soon to a pointer)
  480. *
  481. * Perform the final unregister of an IDE interface. At the moment
  482. * we don't refcount interfaces so this will also get split up.
  483. *
  484. * Locking:
  485. * The caller must not hold the IDE locks
  486. * The drive present/vanishing is not yet properly locked
  487. * Take care with the callbacks. These have been split to avoid
  488. * deadlocking the IDE layer. The shutdown callback is called
  489. * before we take the lock and free resources. It is up to the
  490. * caller to be sure there is no pending I/O here, and that
  491. * the interface will not be reopened (present/vanishing locking
  492. * isn't yet done BTW). After we commit to the final kill we
  493. * call the cleanup callback with the ide locks held.
  494. *
  495. * Unregister restores the hwif structures to the default state.
  496. * This is raving bonkers.
  497. */
  498. void ide_unregister(unsigned int index)
  499. {
  500. ide_drive_t *drive;
  501. ide_hwif_t *hwif, *g;
  502. static ide_hwif_t tmp_hwif; /* protected by ide_cfg_mtx */
  503. ide_hwgroup_t *hwgroup;
  504. int irq_count = 0, unit;
  505. BUG_ON(index >= MAX_HWIFS);
  506. BUG_ON(in_interrupt());
  507. BUG_ON(irqs_disabled());
  508. mutex_lock(&ide_cfg_mtx);
  509. spin_lock_irq(&ide_lock);
  510. hwif = &ide_hwifs[index];
  511. if (!hwif->present)
  512. goto abort;
  513. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  514. drive = &hwif->drives[unit];
  515. if (!drive->present)
  516. continue;
  517. spin_unlock_irq(&ide_lock);
  518. device_unregister(&drive->gendev);
  519. wait_for_completion(&drive->gendev_rel_comp);
  520. spin_lock_irq(&ide_lock);
  521. }
  522. hwif->present = 0;
  523. spin_unlock_irq(&ide_lock);
  524. ide_proc_unregister_port(hwif);
  525. hwgroup = hwif->hwgroup;
  526. /*
  527. * free the irq if we were the only hwif using it
  528. */
  529. g = hwgroup->hwif;
  530. do {
  531. if (g->irq == hwif->irq)
  532. ++irq_count;
  533. g = g->next;
  534. } while (g != hwgroup->hwif);
  535. if (irq_count == 1)
  536. free_irq(hwif->irq, hwgroup);
  537. spin_lock_irq(&ide_lock);
  538. /*
  539. * Note that we only release the standard ports,
  540. * and do not even try to handle any extra ports
  541. * allocated for weird IDE interface chipsets.
  542. */
  543. ide_hwif_release_regions(hwif);
  544. /*
  545. * Remove us from the hwgroup, and free
  546. * the hwgroup if we were the only member
  547. */
  548. if (hwif->next == hwif) {
  549. BUG_ON(hwgroup->hwif != hwif);
  550. kfree(hwgroup);
  551. } else {
  552. /* There is another interface in hwgroup.
  553. * Unlink us, and set hwgroup->drive and ->hwif to
  554. * something sane.
  555. */
  556. g = hwgroup->hwif;
  557. while (g->next != hwif)
  558. g = g->next;
  559. g->next = hwif->next;
  560. if (hwgroup->hwif == hwif) {
  561. /* Chose a random hwif for hwgroup->hwif.
  562. * It's guaranteed that there are no drives
  563. * left in the hwgroup.
  564. */
  565. BUG_ON(hwgroup->drive != NULL);
  566. hwgroup->hwif = g;
  567. }
  568. BUG_ON(hwgroup->hwif == hwif);
  569. }
  570. /* More messed up locking ... */
  571. spin_unlock_irq(&ide_lock);
  572. device_unregister(&hwif->gendev);
  573. wait_for_completion(&hwif->gendev_rel_comp);
  574. /*
  575. * Remove us from the kernel's knowledge
  576. */
  577. blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
  578. kfree(hwif->sg_table);
  579. unregister_blkdev(hwif->major, hwif->name);
  580. spin_lock_irq(&ide_lock);
  581. if (hwif->dma_base) {
  582. (void) ide_release_dma(hwif);
  583. hwif->dma_base = 0;
  584. hwif->dma_master = 0;
  585. hwif->dma_command = 0;
  586. hwif->dma_vendor1 = 0;
  587. hwif->dma_status = 0;
  588. hwif->dma_vendor3 = 0;
  589. hwif->dma_prdtable = 0;
  590. hwif->extra_base = 0;
  591. hwif->extra_ports = 0;
  592. }
  593. /* copy original settings */
  594. tmp_hwif = *hwif;
  595. /* restore hwif data to pristine status */
  596. init_hwif_data(hwif, index);
  597. init_hwif_default(hwif, index);
  598. ide_hwif_restore(hwif, &tmp_hwif);
  599. abort:
  600. spin_unlock_irq(&ide_lock);
  601. mutex_unlock(&ide_cfg_mtx);
  602. }
  603. EXPORT_SYMBOL(ide_unregister);
  604. /**
  605. * ide_setup_ports - set up IDE interface ports
  606. * @hw: register descriptions
  607. * @base: base register
  608. * @offsets: table of register offsets
  609. * @ctrl: control register
  610. * @ack_irq: IRQ ack
  611. * @irq: interrupt lie
  612. *
  613. * Setup hw_regs_t structure described by parameters. You
  614. * may set up the hw structure yourself OR use this routine to
  615. * do it for you. This is basically a helper
  616. *
  617. */
  618. void ide_setup_ports ( hw_regs_t *hw,
  619. unsigned long base, int *offsets,
  620. unsigned long ctrl, unsigned long intr,
  621. ide_ack_intr_t *ack_intr,
  622. /*
  623. * ide_io_ops_t *iops,
  624. */
  625. int irq)
  626. {
  627. int i;
  628. memset(hw, 0, sizeof(hw_regs_t));
  629. for (i = 0; i < IDE_NR_PORTS; i++) {
  630. if (offsets[i] == -1) {
  631. switch(i) {
  632. case IDE_CONTROL_OFFSET:
  633. hw->io_ports[i] = ctrl;
  634. break;
  635. #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
  636. case IDE_IRQ_OFFSET:
  637. hw->io_ports[i] = intr;
  638. break;
  639. #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
  640. default:
  641. hw->io_ports[i] = 0;
  642. break;
  643. }
  644. } else {
  645. hw->io_ports[i] = base + offsets[i];
  646. }
  647. }
  648. hw->irq = irq;
  649. hw->dma = NO_DMA;
  650. hw->ack_intr = ack_intr;
  651. /*
  652. * hw->iops = iops;
  653. */
  654. }
  655. /**
  656. * ide_register_hw_with_fixup - register IDE interface
  657. * @hw: hardware registers
  658. * @initializing: set while initializing built-in drivers
  659. * @hwifp: pointer to returned hwif
  660. * @fixup: fixup function
  661. *
  662. * Register an IDE interface, specifying exactly the registers etc.
  663. * Set init=1 iff calling before probes have taken place.
  664. *
  665. * Returns -1 on error.
  666. */
  667. int ide_register_hw_with_fixup(hw_regs_t *hw, int initializing,
  668. ide_hwif_t **hwifp,
  669. void(*fixup)(ide_hwif_t *hwif))
  670. {
  671. int index, retry = 1;
  672. ide_hwif_t *hwif;
  673. do {
  674. for (index = 0; index < MAX_HWIFS; ++index) {
  675. hwif = &ide_hwifs[index];
  676. if (hwif->hw.io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
  677. goto found;
  678. }
  679. for (index = 0; index < MAX_HWIFS; ++index) {
  680. hwif = &ide_hwifs[index];
  681. if (hwif->hold)
  682. continue;
  683. if ((!hwif->present && !hwif->mate && !initializing) ||
  684. (!hwif->hw.io_ports[IDE_DATA_OFFSET] && initializing))
  685. goto found;
  686. }
  687. for (index = 0; index < MAX_HWIFS; index++)
  688. ide_unregister(index);
  689. } while (retry--);
  690. return -1;
  691. found:
  692. if (hwif->present)
  693. ide_unregister(index);
  694. else if (!hwif->hold) {
  695. init_hwif_data(hwif, index);
  696. init_hwif_default(hwif, index);
  697. }
  698. if (hwif->present)
  699. return -1;
  700. memcpy(&hwif->hw, hw, sizeof(*hw));
  701. memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->hw.io_ports));
  702. hwif->irq = hw->irq;
  703. hwif->noprobe = 0;
  704. hwif->chipset = hw->chipset;
  705. hwif->gendev.parent = hw->dev;
  706. if (!initializing) {
  707. probe_hwif_init_with_fixup(hwif, fixup);
  708. ide_proc_register_port(hwif);
  709. }
  710. if (hwifp)
  711. *hwifp = hwif;
  712. return (initializing || hwif->present) ? index : -1;
  713. }
  714. EXPORT_SYMBOL(ide_register_hw_with_fixup);
  715. int ide_register_hw(hw_regs_t *hw, int initializing, ide_hwif_t **hwifp)
  716. {
  717. return ide_register_hw_with_fixup(hw, initializing, hwifp, NULL);
  718. }
  719. EXPORT_SYMBOL(ide_register_hw);
  720. /*
  721. * Locks for IDE setting functionality
  722. */
  723. DEFINE_MUTEX(ide_setting_mtx);
  724. EXPORT_SYMBOL_GPL(ide_setting_mtx);
  725. /**
  726. * ide_spin_wait_hwgroup - wait for group
  727. * @drive: drive in the group
  728. *
  729. * Wait for an IDE device group to go non busy and then return
  730. * holding the ide_lock which guards the hwgroup->busy status
  731. * and right to use it.
  732. */
  733. int ide_spin_wait_hwgroup (ide_drive_t *drive)
  734. {
  735. ide_hwgroup_t *hwgroup = HWGROUP(drive);
  736. unsigned long timeout = jiffies + (3 * HZ);
  737. spin_lock_irq(&ide_lock);
  738. while (hwgroup->busy) {
  739. unsigned long lflags;
  740. spin_unlock_irq(&ide_lock);
  741. local_irq_set(lflags);
  742. if (time_after(jiffies, timeout)) {
  743. local_irq_restore(lflags);
  744. printk(KERN_ERR "%s: channel busy\n", drive->name);
  745. return -EBUSY;
  746. }
  747. local_irq_restore(lflags);
  748. spin_lock_irq(&ide_lock);
  749. }
  750. return 0;
  751. }
  752. EXPORT_SYMBOL(ide_spin_wait_hwgroup);
  753. int set_io_32bit(ide_drive_t *drive, int arg)
  754. {
  755. if (drive->no_io_32bit)
  756. return -EPERM;
  757. if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
  758. return -EINVAL;
  759. drive->io_32bit = arg;
  760. #ifdef CONFIG_BLK_DEV_DTC2278
  761. if (HWIF(drive)->chipset == ide_dtc2278)
  762. HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
  763. #endif /* CONFIG_BLK_DEV_DTC2278 */
  764. return 0;
  765. }
  766. static int set_ksettings(ide_drive_t *drive, int arg)
  767. {
  768. if (arg < 0 || arg > 1)
  769. return -EINVAL;
  770. if (ide_spin_wait_hwgroup(drive))
  771. return -EBUSY;
  772. drive->keep_settings = arg;
  773. spin_unlock_irq(&ide_lock);
  774. return 0;
  775. }
  776. int set_using_dma(ide_drive_t *drive, int arg)
  777. {
  778. #ifdef CONFIG_BLK_DEV_IDEDMA
  779. ide_hwif_t *hwif = drive->hwif;
  780. int err = -EPERM;
  781. if (arg < 0 || arg > 1)
  782. return -EINVAL;
  783. if (!drive->id || !(drive->id->capability & 1))
  784. goto out;
  785. if (hwif->ide_dma_check == NULL)
  786. goto out;
  787. err = -EBUSY;
  788. if (ide_spin_wait_hwgroup(drive))
  789. goto out;
  790. /*
  791. * set ->busy flag, unlock and let it ride
  792. */
  793. hwif->hwgroup->busy = 1;
  794. spin_unlock_irq(&ide_lock);
  795. err = 0;
  796. if (arg) {
  797. hwif->dma_off_quietly(drive);
  798. if (ide_set_dma(drive) || hwif->ide_dma_on(drive))
  799. err = -EIO;
  800. } else
  801. ide_dma_off(drive);
  802. /*
  803. * lock, clear ->busy flag and unlock before leaving
  804. */
  805. spin_lock_irq(&ide_lock);
  806. hwif->hwgroup->busy = 0;
  807. spin_unlock_irq(&ide_lock);
  808. out:
  809. return err;
  810. #else
  811. if (arg < 0 || arg > 1)
  812. return -EINVAL;
  813. return -EPERM;
  814. #endif
  815. }
  816. int set_pio_mode(ide_drive_t *drive, int arg)
  817. {
  818. struct request rq;
  819. if (arg < 0 || arg > 255)
  820. return -EINVAL;
  821. if (!HWIF(drive)->tuneproc)
  822. return -ENOSYS;
  823. if (drive->special.b.set_tune)
  824. return -EBUSY;
  825. ide_init_drive_cmd(&rq);
  826. drive->tune_req = (u8) arg;
  827. drive->special.b.set_tune = 1;
  828. (void) ide_do_drive_cmd(drive, &rq, ide_wait);
  829. return 0;
  830. }
  831. static int set_unmaskirq(ide_drive_t *drive, int arg)
  832. {
  833. if (drive->no_unmask)
  834. return -EPERM;
  835. if (arg < 0 || arg > 1)
  836. return -EINVAL;
  837. if (ide_spin_wait_hwgroup(drive))
  838. return -EBUSY;
  839. drive->unmask = arg;
  840. spin_unlock_irq(&ide_lock);
  841. return 0;
  842. }
  843. /**
  844. * system_bus_clock - clock guess
  845. *
  846. * External version of the bus clock guess used by very old IDE drivers
  847. * for things like VLB timings. Should not be used.
  848. */
  849. int system_bus_clock (void)
  850. {
  851. return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
  852. }
  853. EXPORT_SYMBOL(system_bus_clock);
  854. static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
  855. {
  856. ide_drive_t *drive = dev->driver_data;
  857. ide_hwif_t *hwif = HWIF(drive);
  858. struct request rq;
  859. struct request_pm_state rqpm;
  860. ide_task_t args;
  861. /* Call ACPI _GTM only once */
  862. if (!(drive->dn % 2))
  863. ide_acpi_get_timing(hwif);
  864. memset(&rq, 0, sizeof(rq));
  865. memset(&rqpm, 0, sizeof(rqpm));
  866. memset(&args, 0, sizeof(args));
  867. rq.cmd_type = REQ_TYPE_PM_SUSPEND;
  868. rq.special = &args;
  869. rq.data = &rqpm;
  870. rqpm.pm_step = ide_pm_state_start_suspend;
  871. if (mesg.event == PM_EVENT_PRETHAW)
  872. mesg.event = PM_EVENT_FREEZE;
  873. rqpm.pm_state = mesg.event;
  874. return ide_do_drive_cmd(drive, &rq, ide_wait);
  875. }
  876. static int generic_ide_resume(struct device *dev)
  877. {
  878. ide_drive_t *drive = dev->driver_data;
  879. ide_hwif_t *hwif = HWIF(drive);
  880. struct request rq;
  881. struct request_pm_state rqpm;
  882. ide_task_t args;
  883. int err;
  884. /* Call ACPI _STM only once */
  885. if (!(drive->dn % 2))
  886. ide_acpi_push_timing(hwif);
  887. ide_acpi_exec_tfs(drive);
  888. memset(&rq, 0, sizeof(rq));
  889. memset(&rqpm, 0, sizeof(rqpm));
  890. memset(&args, 0, sizeof(args));
  891. rq.cmd_type = REQ_TYPE_PM_RESUME;
  892. rq.special = &args;
  893. rq.data = &rqpm;
  894. rqpm.pm_step = ide_pm_state_start_resume;
  895. rqpm.pm_state = PM_EVENT_ON;
  896. err = ide_do_drive_cmd(drive, &rq, ide_head_wait);
  897. if (err == 0 && dev->driver) {
  898. ide_driver_t *drv = to_ide_driver(dev->driver);
  899. if (drv->resume)
  900. drv->resume(drive);
  901. }
  902. return err;
  903. }
  904. int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
  905. unsigned int cmd, unsigned long arg)
  906. {
  907. unsigned long flags;
  908. ide_driver_t *drv;
  909. void __user *p = (void __user *)arg;
  910. int err = 0, (*setfunc)(ide_drive_t *, int);
  911. u8 *val;
  912. switch (cmd) {
  913. case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val;
  914. case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
  915. case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val;
  916. case HDIO_GET_DMA: val = &drive->using_dma; goto read_val;
  917. case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val;
  918. case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val;
  919. case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val;
  920. case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val;
  921. case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val;
  922. }
  923. switch (cmd) {
  924. case HDIO_OBSOLETE_IDENTITY:
  925. case HDIO_GET_IDENTITY:
  926. if (bdev != bdev->bd_contains)
  927. return -EINVAL;
  928. if (drive->id_read == 0)
  929. return -ENOMSG;
  930. if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
  931. return -EFAULT;
  932. return 0;
  933. case HDIO_GET_NICE:
  934. return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
  935. drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
  936. drive->nice0 << IDE_NICE_0 |
  937. drive->nice1 << IDE_NICE_1 |
  938. drive->nice2 << IDE_NICE_2,
  939. (long __user *) arg);
  940. #ifdef CONFIG_IDE_TASK_IOCTL
  941. case HDIO_DRIVE_TASKFILE:
  942. if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
  943. return -EACCES;
  944. switch(drive->media) {
  945. case ide_disk:
  946. return ide_taskfile_ioctl(drive, cmd, arg);
  947. default:
  948. return -ENOMSG;
  949. }
  950. #endif /* CONFIG_IDE_TASK_IOCTL */
  951. case HDIO_DRIVE_CMD:
  952. if (!capable(CAP_SYS_RAWIO))
  953. return -EACCES;
  954. return ide_cmd_ioctl(drive, cmd, arg);
  955. case HDIO_DRIVE_TASK:
  956. if (!capable(CAP_SYS_RAWIO))
  957. return -EACCES;
  958. return ide_task_ioctl(drive, cmd, arg);
  959. case HDIO_SCAN_HWIF:
  960. {
  961. hw_regs_t hw;
  962. int args[3];
  963. if (!capable(CAP_SYS_RAWIO)) return -EACCES;
  964. if (copy_from_user(args, p, 3 * sizeof(int)))
  965. return -EFAULT;
  966. memset(&hw, 0, sizeof(hw));
  967. ide_init_hwif_ports(&hw, (unsigned long) args[0],
  968. (unsigned long) args[1], NULL);
  969. hw.irq = args[2];
  970. if (ide_register_hw(&hw, 0, NULL) == -1)
  971. return -EIO;
  972. return 0;
  973. }
  974. case HDIO_UNREGISTER_HWIF:
  975. if (!capable(CAP_SYS_RAWIO)) return -EACCES;
  976. /* (arg > MAX_HWIFS) checked in function */
  977. ide_unregister(arg);
  978. return 0;
  979. case HDIO_SET_NICE:
  980. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  981. if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
  982. return -EPERM;
  983. drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
  984. drv = *(ide_driver_t **)bdev->bd_disk->private_data;
  985. if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
  986. drive->dsc_overlap = 0;
  987. return -EPERM;
  988. }
  989. drive->nice1 = (arg >> IDE_NICE_1) & 1;
  990. return 0;
  991. case HDIO_DRIVE_RESET:
  992. {
  993. unsigned long flags;
  994. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  995. /*
  996. * Abort the current command on the
  997. * group if there is one, taking
  998. * care not to allow anything else
  999. * to be queued and to die on the
  1000. * spot if we miss one somehow
  1001. */
  1002. spin_lock_irqsave(&ide_lock, flags);
  1003. if (HWGROUP(drive)->resetting) {
  1004. spin_unlock_irqrestore(&ide_lock, flags);
  1005. return -EBUSY;
  1006. }
  1007. ide_abort(drive, "drive reset");
  1008. BUG_ON(HWGROUP(drive)->handler);
  1009. /* Ensure nothing gets queued after we
  1010. drop the lock. Reset will clear the busy */
  1011. HWGROUP(drive)->busy = 1;
  1012. spin_unlock_irqrestore(&ide_lock, flags);
  1013. (void) ide_do_reset(drive);
  1014. return 0;
  1015. }
  1016. case CDROMEJECT:
  1017. case CDROMCLOSETRAY:
  1018. return scsi_cmd_ioctl(file, bdev->bd_disk->queue, bdev->bd_disk, cmd, p);
  1019. case HDIO_GET_BUSSTATE:
  1020. if (!capable(CAP_SYS_ADMIN))
  1021. return -EACCES;
  1022. if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
  1023. return -EFAULT;
  1024. return 0;
  1025. case HDIO_SET_BUSSTATE:
  1026. if (!capable(CAP_SYS_ADMIN))
  1027. return -EACCES;
  1028. if (HWIF(drive)->busproc)
  1029. return HWIF(drive)->busproc(drive, (int)arg);
  1030. return -EOPNOTSUPP;
  1031. default:
  1032. return -EINVAL;
  1033. }
  1034. read_val:
  1035. mutex_lock(&ide_setting_mtx);
  1036. spin_lock_irqsave(&ide_lock, flags);
  1037. err = *val;
  1038. spin_unlock_irqrestore(&ide_lock, flags);
  1039. mutex_unlock(&ide_setting_mtx);
  1040. return err >= 0 ? put_user(err, (long __user *)arg) : err;
  1041. set_val:
  1042. if (bdev != bdev->bd_contains)
  1043. err = -EINVAL;
  1044. else {
  1045. if (!capable(CAP_SYS_ADMIN))
  1046. err = -EACCES;
  1047. else {
  1048. mutex_lock(&ide_setting_mtx);
  1049. err = setfunc(drive, arg);
  1050. mutex_unlock(&ide_setting_mtx);
  1051. }
  1052. }
  1053. return err;
  1054. }
  1055. EXPORT_SYMBOL(generic_ide_ioctl);
  1056. /*
  1057. * stridx() returns the offset of c within s,
  1058. * or -1 if c is '\0' or not found within s.
  1059. */
  1060. static int __init stridx (const char *s, char c)
  1061. {
  1062. char *i = strchr(s, c);
  1063. return (i && c) ? i - s : -1;
  1064. }
  1065. /*
  1066. * match_parm() does parsing for ide_setup():
  1067. *
  1068. * 1. the first char of s must be '='.
  1069. * 2. if the remainder matches one of the supplied keywords,
  1070. * the index (1 based) of the keyword is negated and returned.
  1071. * 3. if the remainder is a series of no more than max_vals numbers
  1072. * separated by commas, the numbers are saved in vals[] and a
  1073. * count of how many were saved is returned. Base10 is assumed,
  1074. * and base16 is allowed when prefixed with "0x".
  1075. * 4. otherwise, zero is returned.
  1076. */
  1077. static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
  1078. {
  1079. static const char *decimal = "0123456789";
  1080. static const char *hex = "0123456789abcdef";
  1081. int i, n;
  1082. if (*s++ == '=') {
  1083. /*
  1084. * Try matching against the supplied keywords,
  1085. * and return -(index+1) if we match one
  1086. */
  1087. if (keywords != NULL) {
  1088. for (i = 0; *keywords != NULL; ++i) {
  1089. if (!strcmp(s, *keywords++))
  1090. return -(i+1);
  1091. }
  1092. }
  1093. /*
  1094. * Look for a series of no more than "max_vals"
  1095. * numeric values separated by commas, in base10,
  1096. * or base16 when prefixed with "0x".
  1097. * Return a count of how many were found.
  1098. */
  1099. for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
  1100. vals[n] = i;
  1101. while ((i = stridx(decimal, *++s)) >= 0)
  1102. vals[n] = (vals[n] * 10) + i;
  1103. if (*s == 'x' && !vals[n]) {
  1104. while ((i = stridx(hex, *++s)) >= 0)
  1105. vals[n] = (vals[n] * 0x10) + i;
  1106. }
  1107. if (++n == max_vals)
  1108. break;
  1109. if (*s == ',' || *s == ';')
  1110. ++s;
  1111. }
  1112. if (!*s)
  1113. return n;
  1114. }
  1115. return 0; /* zero = nothing matched */
  1116. }
  1117. #ifdef CONFIG_BLK_DEV_ALI14XX
  1118. extern int probe_ali14xx;
  1119. extern int ali14xx_init(void);
  1120. #endif
  1121. #ifdef CONFIG_BLK_DEV_UMC8672
  1122. extern int probe_umc8672;
  1123. extern int umc8672_init(void);
  1124. #endif
  1125. #ifdef CONFIG_BLK_DEV_DTC2278
  1126. extern int probe_dtc2278;
  1127. extern int dtc2278_init(void);
  1128. #endif
  1129. #ifdef CONFIG_BLK_DEV_HT6560B
  1130. extern int probe_ht6560b;
  1131. extern int ht6560b_init(void);
  1132. #endif
  1133. #ifdef CONFIG_BLK_DEV_QD65XX
  1134. extern int probe_qd65xx;
  1135. extern int qd65xx_init(void);
  1136. #endif
  1137. static int __initdata is_chipset_set[MAX_HWIFS];
  1138. /*
  1139. * ide_setup() gets called VERY EARLY during initialization,
  1140. * to handle kernel "command line" strings beginning with "hdx=" or "ide".
  1141. *
  1142. * Remember to update Documentation/ide.txt if you change something here.
  1143. */
  1144. static int __init ide_setup(char *s)
  1145. {
  1146. int i, vals[3];
  1147. ide_hwif_t *hwif;
  1148. ide_drive_t *drive;
  1149. unsigned int hw, unit;
  1150. const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
  1151. const char max_hwif = '0' + (MAX_HWIFS - 1);
  1152. if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
  1153. return 0; /* driver and not us */
  1154. if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
  1155. return 0;
  1156. printk(KERN_INFO "ide_setup: %s", s);
  1157. init_ide_data ();
  1158. #ifdef CONFIG_BLK_DEV_IDEDOUBLER
  1159. if (!strcmp(s, "ide=doubler")) {
  1160. extern int ide_doubler;
  1161. printk(" : Enabled support for IDE doublers\n");
  1162. ide_doubler = 1;
  1163. return 1;
  1164. }
  1165. #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
  1166. if (!strcmp(s, "ide=nodma")) {
  1167. printk(" : Prevented DMA\n");
  1168. noautodma = 1;
  1169. return 1;
  1170. }
  1171. #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
  1172. if (!strcmp(s, "ide=reverse")) {
  1173. ide_scan_direction = 1;
  1174. printk(" : Enabled support for IDE inverse scan order.\n");
  1175. return 1;
  1176. }
  1177. #endif
  1178. #ifdef CONFIG_BLK_DEV_IDEACPI
  1179. if (!strcmp(s, "ide=noacpi")) {
  1180. //printk(" : Disable IDE ACPI support.\n");
  1181. ide_noacpi = 1;
  1182. return 1;
  1183. }
  1184. if (!strcmp(s, "ide=acpigtf")) {
  1185. //printk(" : Enable IDE ACPI _GTF support.\n");
  1186. ide_noacpitfs = 0;
  1187. return 1;
  1188. }
  1189. if (!strcmp(s, "ide=acpionboot")) {
  1190. //printk(" : Call IDE ACPI methods on boot.\n");
  1191. ide_noacpionboot = 0;
  1192. return 1;
  1193. }
  1194. #endif /* CONFIG_BLK_DEV_IDEACPI */
  1195. /*
  1196. * Look for drive options: "hdx="
  1197. */
  1198. if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
  1199. const char *hd_words[] = {
  1200. "none", "noprobe", "nowerr", "cdrom", "minus5",
  1201. "autotune", "noautotune", "minus8", "swapdata", "bswap",
  1202. "noflush", "remap", "remap63", "scsi", NULL };
  1203. unit = s[2] - 'a';
  1204. hw = unit / MAX_DRIVES;
  1205. unit = unit % MAX_DRIVES;
  1206. hwif = &ide_hwifs[hw];
  1207. drive = &hwif->drives[unit];
  1208. if (strncmp(s + 4, "ide-", 4) == 0) {
  1209. strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
  1210. goto done;
  1211. }
  1212. switch (match_parm(&s[3], hd_words, vals, 3)) {
  1213. case -1: /* "none" */
  1214. case -2: /* "noprobe" */
  1215. drive->noprobe = 1;
  1216. goto done;
  1217. case -3: /* "nowerr" */
  1218. drive->bad_wstat = BAD_R_STAT;
  1219. hwif->noprobe = 0;
  1220. goto done;
  1221. case -4: /* "cdrom" */
  1222. drive->present = 1;
  1223. drive->media = ide_cdrom;
  1224. /* an ATAPI device ignores DRDY */
  1225. drive->ready_stat = 0;
  1226. hwif->noprobe = 0;
  1227. goto done;
  1228. case -6: /* "autotune" */
  1229. drive->autotune = IDE_TUNE_AUTO;
  1230. goto obsolete_option;
  1231. case -7: /* "noautotune" */
  1232. drive->autotune = IDE_TUNE_NOAUTO;
  1233. goto obsolete_option;
  1234. case -9: /* "swapdata" */
  1235. case -10: /* "bswap" */
  1236. drive->bswap = 1;
  1237. goto done;
  1238. case -11: /* noflush */
  1239. drive->noflush = 1;
  1240. goto done;
  1241. case -12: /* "remap" */
  1242. drive->remap_0_to_1 = 1;
  1243. goto done;
  1244. case -13: /* "remap63" */
  1245. drive->sect0 = 63;
  1246. goto done;
  1247. case -14: /* "scsi" */
  1248. drive->scsi = 1;
  1249. goto done;
  1250. case 3: /* cyl,head,sect */
  1251. drive->media = ide_disk;
  1252. drive->ready_stat = READY_STAT;
  1253. drive->cyl = drive->bios_cyl = vals[0];
  1254. drive->head = drive->bios_head = vals[1];
  1255. drive->sect = drive->bios_sect = vals[2];
  1256. drive->present = 1;
  1257. drive->forced_geom = 1;
  1258. hwif->noprobe = 0;
  1259. goto done;
  1260. default:
  1261. goto bad_option;
  1262. }
  1263. }
  1264. if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
  1265. goto bad_option;
  1266. /*
  1267. * Look for bus speed option: "idebus="
  1268. */
  1269. if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
  1270. if (match_parm(&s[6], NULL, vals, 1) != 1)
  1271. goto bad_option;
  1272. if (vals[0] >= 20 && vals[0] <= 66) {
  1273. idebus_parameter = vals[0];
  1274. } else
  1275. printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
  1276. goto done;
  1277. }
  1278. /*
  1279. * Look for interface options: "idex="
  1280. */
  1281. if (s[3] >= '0' && s[3] <= max_hwif) {
  1282. /*
  1283. * Be VERY CAREFUL changing this: note hardcoded indexes below
  1284. * (-8, -9, -10) are reserved to ease the hardcoding.
  1285. */
  1286. static const char *ide_words[] = {
  1287. "noprobe", "serialize", "minus3", "minus4",
  1288. "reset", "dma", "ata66", "minus8", "minus9",
  1289. "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
  1290. "dtc2278", "umc8672", "ali14xx", NULL };
  1291. hw = s[3] - '0';
  1292. hwif = &ide_hwifs[hw];
  1293. i = match_parm(&s[4], ide_words, vals, 3);
  1294. /*
  1295. * Cryptic check to ensure chipset not already set for hwif.
  1296. * Note: we can't depend on hwif->chipset here.
  1297. */
  1298. if ((i >= -18 && i <= -11) || (i > 0 && i <= 3)) {
  1299. /* chipset already specified */
  1300. if (is_chipset_set[hw])
  1301. goto bad_option;
  1302. if (i > -18 && i <= -11) {
  1303. /* these drivers are for "ide0=" only */
  1304. if (hw != 0)
  1305. goto bad_hwif;
  1306. /* chipset already specified for 2nd port */
  1307. if (is_chipset_set[hw+1])
  1308. goto bad_option;
  1309. }
  1310. is_chipset_set[hw] = 1;
  1311. printk("\n");
  1312. }
  1313. switch (i) {
  1314. #ifdef CONFIG_BLK_DEV_ALI14XX
  1315. case -17: /* "ali14xx" */
  1316. probe_ali14xx = 1;
  1317. goto done;
  1318. #endif
  1319. #ifdef CONFIG_BLK_DEV_UMC8672
  1320. case -16: /* "umc8672" */
  1321. probe_umc8672 = 1;
  1322. goto done;
  1323. #endif
  1324. #ifdef CONFIG_BLK_DEV_DTC2278
  1325. case -15: /* "dtc2278" */
  1326. probe_dtc2278 = 1;
  1327. goto done;
  1328. #endif
  1329. #ifdef CONFIG_BLK_DEV_CMD640
  1330. case -14: /* "cmd640_vlb" */
  1331. {
  1332. extern int cmd640_vlb; /* flag for cmd640.c */
  1333. cmd640_vlb = 1;
  1334. goto done;
  1335. }
  1336. #endif
  1337. #ifdef CONFIG_BLK_DEV_HT6560B
  1338. case -13: /* "ht6560b" */
  1339. probe_ht6560b = 1;
  1340. goto done;
  1341. #endif
  1342. #ifdef CONFIG_BLK_DEV_QD65XX
  1343. case -12: /* "qd65xx" */
  1344. probe_qd65xx = 1;
  1345. goto done;
  1346. #endif
  1347. #ifdef CONFIG_BLK_DEV_4DRIVES
  1348. case -11: /* "four" drives on one set of ports */
  1349. {
  1350. ide_hwif_t *mate = &ide_hwifs[hw^1];
  1351. mate->drives[0].select.all ^= 0x20;
  1352. mate->drives[1].select.all ^= 0x20;
  1353. hwif->chipset = mate->chipset = ide_4drives;
  1354. mate->irq = hwif->irq;
  1355. memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
  1356. hwif->mate = mate;
  1357. mate->mate = hwif;
  1358. hwif->serialized = mate->serialized = 1;
  1359. goto obsolete_option;
  1360. }
  1361. #endif /* CONFIG_BLK_DEV_4DRIVES */
  1362. case -10: /* minus10 */
  1363. case -9: /* minus9 */
  1364. case -8: /* minus8 */
  1365. case -4:
  1366. case -3:
  1367. goto bad_option;
  1368. case -7: /* ata66 */
  1369. #ifdef CONFIG_BLK_DEV_IDEPCI
  1370. /*
  1371. * Use ATA_CBL_PATA40_SHORT so drive side
  1372. * cable detection is also overriden.
  1373. */
  1374. hwif->cbl = ATA_CBL_PATA40_SHORT;
  1375. goto obsolete_option;
  1376. #else
  1377. goto bad_hwif;
  1378. #endif
  1379. case -6: /* dma */
  1380. hwif->autodma = 1;
  1381. goto obsolete_option;
  1382. case -5: /* "reset" */
  1383. hwif->reset = 1;
  1384. goto obsolete_option;
  1385. case -2: /* "serialize" */
  1386. hwif->mate = &ide_hwifs[hw^1];
  1387. hwif->mate->mate = hwif;
  1388. hwif->serialized = hwif->mate->serialized = 1;
  1389. goto obsolete_option;
  1390. case -1: /* "noprobe" */
  1391. hwif->noprobe = 1;
  1392. goto done;
  1393. case 1: /* base */
  1394. vals[1] = vals[0] + 0x206; /* default ctl */
  1395. case 2: /* base,ctl */
  1396. vals[2] = 0; /* default irq = probe for it */
  1397. case 3: /* base,ctl,irq */
  1398. hwif->hw.irq = vals[2];
  1399. ide_init_hwif_ports(&hwif->hw, (unsigned long) vals[0], (unsigned long) vals[1], &hwif->irq);
  1400. memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
  1401. hwif->irq = vals[2];
  1402. hwif->noprobe = 0;
  1403. hwif->chipset = ide_forced;
  1404. goto obsolete_option;
  1405. case 0: goto bad_option;
  1406. default:
  1407. printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
  1408. return 1;
  1409. }
  1410. }
  1411. bad_option:
  1412. printk(" -- BAD OPTION\n");
  1413. return 1;
  1414. obsolete_option:
  1415. printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
  1416. return 1;
  1417. bad_hwif:
  1418. printk("-- NOT SUPPORTED ON ide%d", hw);
  1419. done:
  1420. printk("\n");
  1421. return 1;
  1422. }
  1423. extern void __init pnpide_init(void);
  1424. extern void __exit pnpide_exit(void);
  1425. extern void __init h8300_ide_init(void);
  1426. /*
  1427. * probe_for_hwifs() finds/initializes "known" IDE interfaces
  1428. */
  1429. static void __init probe_for_hwifs (void)
  1430. {
  1431. #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
  1432. ide_scan_pcibus(ide_scan_direction);
  1433. #endif
  1434. #ifdef CONFIG_ETRAX_IDE
  1435. {
  1436. extern void init_e100_ide(void);
  1437. init_e100_ide();
  1438. }
  1439. #endif /* CONFIG_ETRAX_IDE */
  1440. #ifdef CONFIG_BLK_DEV_CMD640
  1441. {
  1442. extern void ide_probe_for_cmd640x(void);
  1443. ide_probe_for_cmd640x();
  1444. }
  1445. #endif /* CONFIG_BLK_DEV_CMD640 */
  1446. #ifdef CONFIG_BLK_DEV_IDE_PMAC
  1447. {
  1448. extern int pmac_ide_probe(void);
  1449. (void)pmac_ide_probe();
  1450. }
  1451. #endif /* CONFIG_BLK_DEV_IDE_PMAC */
  1452. #ifdef CONFIG_BLK_DEV_GAYLE
  1453. {
  1454. extern void gayle_init(void);
  1455. gayle_init();
  1456. }
  1457. #endif /* CONFIG_BLK_DEV_GAYLE */
  1458. #ifdef CONFIG_BLK_DEV_FALCON_IDE
  1459. {
  1460. extern void falconide_init(void);
  1461. falconide_init();
  1462. }
  1463. #endif /* CONFIG_BLK_DEV_FALCON_IDE */
  1464. #ifdef CONFIG_BLK_DEV_MAC_IDE
  1465. {
  1466. extern void macide_init(void);
  1467. macide_init();
  1468. }
  1469. #endif /* CONFIG_BLK_DEV_MAC_IDE */
  1470. #ifdef CONFIG_BLK_DEV_Q40IDE
  1471. {
  1472. extern void q40ide_init(void);
  1473. q40ide_init();
  1474. }
  1475. #endif /* CONFIG_BLK_DEV_Q40IDE */
  1476. #ifdef CONFIG_BLK_DEV_BUDDHA
  1477. {
  1478. extern void buddha_init(void);
  1479. buddha_init();
  1480. }
  1481. #endif /* CONFIG_BLK_DEV_BUDDHA */
  1482. #ifdef CONFIG_BLK_DEV_IDEPNP
  1483. pnpide_init();
  1484. #endif
  1485. #ifdef CONFIG_H8300
  1486. h8300_ide_init();
  1487. #endif
  1488. }
  1489. /*
  1490. * Probe module
  1491. */
  1492. EXPORT_SYMBOL(ide_lock);
  1493. static int ide_bus_match(struct device *dev, struct device_driver *drv)
  1494. {
  1495. return 1;
  1496. }
  1497. static char *media_string(ide_drive_t *drive)
  1498. {
  1499. switch (drive->media) {
  1500. case ide_disk:
  1501. return "disk";
  1502. case ide_cdrom:
  1503. return "cdrom";
  1504. case ide_tape:
  1505. return "tape";
  1506. case ide_floppy:
  1507. return "floppy";
  1508. case ide_optical:
  1509. return "optical";
  1510. default:
  1511. return "UNKNOWN";
  1512. }
  1513. }
  1514. static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
  1515. {
  1516. ide_drive_t *drive = to_ide_device(dev);
  1517. return sprintf(buf, "%s\n", media_string(drive));
  1518. }
  1519. static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
  1520. {
  1521. ide_drive_t *drive = to_ide_device(dev);
  1522. return sprintf(buf, "%s\n", drive->name);
  1523. }
  1524. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
  1525. {
  1526. ide_drive_t *drive = to_ide_device(dev);
  1527. return sprintf(buf, "ide:m-%s\n", media_string(drive));
  1528. }
  1529. static struct device_attribute ide_dev_attrs[] = {
  1530. __ATTR_RO(media),
  1531. __ATTR_RO(drivename),
  1532. __ATTR_RO(modalias),
  1533. __ATTR_NULL
  1534. };
  1535. static int ide_uevent(struct device *dev, char **envp, int num_envp,
  1536. char *buffer, int buffer_size)
  1537. {
  1538. ide_drive_t *drive = to_ide_device(dev);
  1539. int i = 0;
  1540. int length = 0;
  1541. add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
  1542. "MEDIA=%s", media_string(drive));
  1543. add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
  1544. "DRIVENAME=%s", drive->name);
  1545. add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
  1546. "MODALIAS=ide:m-%s", media_string(drive));
  1547. envp[i] = NULL;
  1548. return 0;
  1549. }
  1550. static int generic_ide_probe(struct device *dev)
  1551. {
  1552. ide_drive_t *drive = to_ide_device(dev);
  1553. ide_driver_t *drv = to_ide_driver(dev->driver);
  1554. return drv->probe ? drv->probe(drive) : -ENODEV;
  1555. }
  1556. static int generic_ide_remove(struct device *dev)
  1557. {
  1558. ide_drive_t *drive = to_ide_device(dev);
  1559. ide_driver_t *drv = to_ide_driver(dev->driver);
  1560. if (drv->remove)
  1561. drv->remove(drive);
  1562. return 0;
  1563. }
  1564. static void generic_ide_shutdown(struct device *dev)
  1565. {
  1566. ide_drive_t *drive = to_ide_device(dev);
  1567. ide_driver_t *drv = to_ide_driver(dev->driver);
  1568. if (dev->driver && drv->shutdown)
  1569. drv->shutdown(drive);
  1570. }
  1571. struct bus_type ide_bus_type = {
  1572. .name = "ide",
  1573. .match = ide_bus_match,
  1574. .uevent = ide_uevent,
  1575. .probe = generic_ide_probe,
  1576. .remove = generic_ide_remove,
  1577. .shutdown = generic_ide_shutdown,
  1578. .dev_attrs = ide_dev_attrs,
  1579. .suspend = generic_ide_suspend,
  1580. .resume = generic_ide_resume,
  1581. };
  1582. EXPORT_SYMBOL_GPL(ide_bus_type);
  1583. /*
  1584. * This is gets invoked once during initialization, to set *everything* up
  1585. */
  1586. static int __init ide_init(void)
  1587. {
  1588. int ret;
  1589. printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
  1590. system_bus_speed = ide_system_bus_speed();
  1591. ret = bus_register(&ide_bus_type);
  1592. if (ret < 0) {
  1593. printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
  1594. return ret;
  1595. }
  1596. init_ide_data();
  1597. proc_ide_create();
  1598. #ifdef CONFIG_BLK_DEV_ALI14XX
  1599. if (probe_ali14xx)
  1600. (void)ali14xx_init();
  1601. #endif
  1602. #ifdef CONFIG_BLK_DEV_UMC8672
  1603. if (probe_umc8672)
  1604. (void)umc8672_init();
  1605. #endif
  1606. #ifdef CONFIG_BLK_DEV_DTC2278
  1607. if (probe_dtc2278)
  1608. (void)dtc2278_init();
  1609. #endif
  1610. #ifdef CONFIG_BLK_DEV_HT6560B
  1611. if (probe_ht6560b)
  1612. (void)ht6560b_init();
  1613. #endif
  1614. #ifdef CONFIG_BLK_DEV_QD65XX
  1615. if (probe_qd65xx)
  1616. (void)qd65xx_init();
  1617. #endif
  1618. /* Probe for special PCI and other "known" interface chipsets. */
  1619. probe_for_hwifs();
  1620. return 0;
  1621. }
  1622. #ifdef MODULE
  1623. static char *options = NULL;
  1624. module_param(options, charp, 0);
  1625. MODULE_LICENSE("GPL");
  1626. static void __init parse_options (char *line)
  1627. {
  1628. char *next = line;
  1629. if (line == NULL || !*line)
  1630. return;
  1631. while ((line = next) != NULL) {
  1632. if ((next = strchr(line,' ')) != NULL)
  1633. *next++ = 0;
  1634. if (!ide_setup(line))
  1635. printk (KERN_INFO "Unknown option '%s'\n", line);
  1636. }
  1637. }
  1638. int __init init_module (void)
  1639. {
  1640. parse_options(options);
  1641. return ide_init();
  1642. }
  1643. void __exit cleanup_module (void)
  1644. {
  1645. int index;
  1646. for (index = 0; index < MAX_HWIFS; ++index)
  1647. ide_unregister(index);
  1648. #ifdef CONFIG_BLK_DEV_IDEPNP
  1649. pnpide_exit();
  1650. #endif
  1651. proc_ide_destroy();
  1652. bus_unregister(&ide_bus_type);
  1653. }
  1654. #else /* !MODULE */
  1655. __setup("", ide_setup);
  1656. module_init(ide_init);
  1657. #endif /* MODULE */