ide.c 48 KB

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