ide.c 48 KB

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