ide.c 57 KB

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