ide.c 55 KB

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