ide.c 55 KB

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