ide.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  1. /*
  2. * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
  3. * Copyrifht (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz
  4. */
  5. /*
  6. * Mostly written by Mark Lord <mlord@pobox.com>
  7. * and Gadi Oxman <gadio@netvision.net.il>
  8. * and Andre Hedrick <andre@linux-ide.org>
  9. *
  10. * See linux/MAINTAINERS for address of current maintainer.
  11. *
  12. * This is the multiple IDE interface driver, as evolved from hd.c.
  13. * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs
  14. * (usually 14 & 15).
  15. * There can be up to two drives per interface, as per the ATA-2 spec.
  16. *
  17. * ...
  18. *
  19. * From hd.c:
  20. * |
  21. * | It traverses the request-list, using interrupts to jump between functions.
  22. * | As nearly all functions can be called within interrupts, we may not sleep.
  23. * | Special care is recommended. Have Fun!
  24. * |
  25. * | modified by Drew Eckhardt to check nr of hd's from the CMOS.
  26. * |
  27. * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
  28. * | in the early extended-partition checks and added DM partitions.
  29. * |
  30. * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
  31. * |
  32. * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
  33. * | and general streamlining by Mark Lord (mlord@pobox.com).
  34. *
  35. * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
  36. *
  37. * Mark Lord (mlord@pobox.com) (IDE Perf.Pkg)
  38. * Delman Lee (delman@ieee.org) ("Mr. atdisk2")
  39. * Scott Snyder (snyder@fnald0.fnal.gov) (ATAPI IDE cd-rom)
  40. *
  41. * This was a rewrite of just about everything from hd.c, though some original
  42. * code is still sprinkled about. Think of it as a major evolution, with
  43. * inspiration from lots of linux users, esp. hamish@zot.apana.org.au
  44. */
  45. #define _IDE_C /* Tell ide.h it's really us */
  46. #include <linux/module.h>
  47. #include <linux/types.h>
  48. #include <linux/string.h>
  49. #include <linux/kernel.h>
  50. #include <linux/timer.h>
  51. #include <linux/mm.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/major.h>
  54. #include <linux/errno.h>
  55. #include <linux/genhd.h>
  56. #include <linux/blkpg.h>
  57. #include <linux/slab.h>
  58. #include <linux/init.h>
  59. #include <linux/pci.h>
  60. #include <linux/delay.h>
  61. #include <linux/ide.h>
  62. #include <linux/completion.h>
  63. #include <linux/reboot.h>
  64. #include <linux/cdrom.h>
  65. #include <linux/seq_file.h>
  66. #include <linux/device.h>
  67. #include <linux/bitops.h>
  68. #include <asm/byteorder.h>
  69. #include <asm/irq.h>
  70. #include <asm/uaccess.h>
  71. #include <asm/io.h>
  72. /* default maximum number of failures */
  73. #define IDE_DEFAULT_MAX_FAILURES 1
  74. struct class *ide_port_class;
  75. static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
  76. IDE2_MAJOR, IDE3_MAJOR,
  77. IDE4_MAJOR, IDE5_MAJOR,
  78. IDE6_MAJOR, IDE7_MAJOR,
  79. IDE8_MAJOR, IDE9_MAJOR };
  80. static int idebus_parameter; /* holds the "idebus=" parameter */
  81. static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */
  82. DEFINE_MUTEX(ide_cfg_mtx);
  83. __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
  84. int noautodma = 0;
  85. #ifdef CONFIG_BLK_DEV_IDEACPI
  86. int ide_noacpi = 0;
  87. int ide_noacpitfs = 1;
  88. int ide_noacpionboot = 1;
  89. #endif
  90. ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
  91. static void ide_port_init_devices_data(ide_hwif_t *);
  92. /*
  93. * Do not even *think* about calling this!
  94. */
  95. void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
  96. {
  97. /* bulk initialize hwif & drive info with zeros */
  98. memset(hwif, 0, sizeof(ide_hwif_t));
  99. /* fill in any non-zero initial values */
  100. hwif->index = index;
  101. hwif->major = ide_hwif_to_major[index];
  102. hwif->name[0] = 'i';
  103. hwif->name[1] = 'd';
  104. hwif->name[2] = 'e';
  105. hwif->name[3] = '0' + index;
  106. hwif->bus_state = BUSSTATE_ON;
  107. init_completion(&hwif->gendev_rel_comp);
  108. default_hwif_iops(hwif);
  109. default_hwif_transport(hwif);
  110. ide_port_init_devices_data(hwif);
  111. }
  112. EXPORT_SYMBOL_GPL(ide_init_port_data);
  113. static void ide_port_init_devices_data(ide_hwif_t *hwif)
  114. {
  115. int unit;
  116. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  117. ide_drive_t *drive = &hwif->drives[unit];
  118. u8 j = (hwif->index * MAX_DRIVES) + unit;
  119. memset(drive, 0, sizeof(*drive));
  120. drive->media = ide_disk;
  121. drive->select.all = (unit<<4)|0xa0;
  122. drive->hwif = hwif;
  123. drive->ctl = 0x08;
  124. drive->ready_stat = READY_STAT;
  125. drive->bad_wstat = BAD_W_STAT;
  126. drive->special.b.recalibrate = 1;
  127. drive->special.b.set_geometry = 1;
  128. drive->name[0] = 'h';
  129. drive->name[1] = 'd';
  130. drive->name[2] = 'a' + j;
  131. drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
  132. INIT_LIST_HEAD(&drive->list);
  133. init_completion(&drive->gendev_rel_comp);
  134. }
  135. }
  136. /*
  137. * init_ide_data() sets reasonable default values into all fields
  138. * of all instances of the hwifs and drives, but only on the first call.
  139. * Subsequent calls have no effect (they don't wipe out anything).
  140. *
  141. * This routine is normally called at driver initialization time,
  142. * but may also be called MUCH earlier during kernel "command-line"
  143. * parameter processing. As such, we cannot depend on any other parts
  144. * of the kernel (such as memory allocation) to be functioning yet.
  145. *
  146. * This is too bad, as otherwise we could dynamically allocate the
  147. * ide_drive_t structs as needed, rather than always consuming memory
  148. * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
  149. *
  150. * FIXME: We should stuff the setup data into __init and copy the
  151. * relevant hwifs/allocate them properly during boot.
  152. */
  153. #define MAGIC_COOKIE 0x12345678
  154. static void __init init_ide_data (void)
  155. {
  156. unsigned int index;
  157. static unsigned long magic_cookie = MAGIC_COOKIE;
  158. if (magic_cookie != MAGIC_COOKIE)
  159. return; /* already initialized */
  160. magic_cookie = 0;
  161. /* Initialise all interface structures */
  162. for (index = 0; index < MAX_HWIFS; ++index) {
  163. ide_hwif_t *hwif = &ide_hwifs[index];
  164. ide_init_port_data(hwif, index);
  165. }
  166. }
  167. /**
  168. * ide_system_bus_speed - guess bus speed
  169. *
  170. * ide_system_bus_speed() returns what we think is the system VESA/PCI
  171. * bus speed (in MHz). This is used for calculating interface PIO timings.
  172. * The default is 40 for known PCI systems, 50 otherwise.
  173. * The "idebus=xx" parameter can be used to override this value.
  174. * The actual value to be used is computed/displayed the first time
  175. * through. Drivers should only use this as a last resort.
  176. *
  177. * Returns a guessed speed in MHz.
  178. */
  179. static int ide_system_bus_speed(void)
  180. {
  181. #ifdef CONFIG_PCI
  182. static struct pci_device_id pci_default[] = {
  183. { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) },
  184. { }
  185. };
  186. #else
  187. #define pci_default 0
  188. #endif /* CONFIG_PCI */
  189. /* user supplied value */
  190. if (idebus_parameter)
  191. return idebus_parameter;
  192. /* safe default value for PCI or VESA and PCI*/
  193. return pci_dev_present(pci_default) ? 33 : 50;
  194. }
  195. static struct resource* hwif_request_region(ide_hwif_t *hwif,
  196. unsigned long addr, int num)
  197. {
  198. struct resource *res = request_region(addr, num, hwif->name);
  199. if (!res)
  200. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
  201. hwif->name, addr, addr+num-1);
  202. return res;
  203. }
  204. /**
  205. * ide_hwif_request_regions - request resources for IDE
  206. * @hwif: interface to use
  207. *
  208. * Requests all the needed resources for an interface.
  209. * Right now core IDE code does this work which is deeply wrong.
  210. * MMIO leaves it to the controller driver,
  211. * PIO will migrate this way over time.
  212. */
  213. int ide_hwif_request_regions(ide_hwif_t *hwif)
  214. {
  215. unsigned long addr;
  216. if (hwif->mmio)
  217. return 0;
  218. addr = hwif->io_ports[IDE_CONTROL_OFFSET];
  219. if (addr && !hwif_request_region(hwif, addr, 1))
  220. goto control_region_busy;
  221. addr = hwif->io_ports[IDE_DATA_OFFSET];
  222. BUG_ON((addr | 7) != hwif->io_ports[IDE_STATUS_OFFSET]);
  223. if (!hwif_request_region(hwif, addr, 8))
  224. goto data_region_busy;
  225. return 0;
  226. data_region_busy:
  227. addr = hwif->io_ports[IDE_CONTROL_OFFSET];
  228. if (addr)
  229. release_region(addr, 1);
  230. control_region_busy:
  231. /* If any errors are return, we drop the hwif interface. */
  232. return -EBUSY;
  233. }
  234. void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
  235. {
  236. ide_hwgroup_t *hwgroup = hwif->hwgroup;
  237. spin_lock_irq(&ide_lock);
  238. /*
  239. * Remove us from the hwgroup, and free
  240. * the hwgroup if we were the only member
  241. */
  242. if (hwif->next == hwif) {
  243. BUG_ON(hwgroup->hwif != hwif);
  244. kfree(hwgroup);
  245. } else {
  246. /* There is another interface in hwgroup.
  247. * Unlink us, and set hwgroup->drive and ->hwif to
  248. * something sane.
  249. */
  250. ide_hwif_t *g = hwgroup->hwif;
  251. while (g->next != hwif)
  252. g = g->next;
  253. g->next = hwif->next;
  254. if (hwgroup->hwif == hwif) {
  255. /* Chose a random hwif for hwgroup->hwif.
  256. * It's guaranteed that there are no drives
  257. * left in the hwgroup.
  258. */
  259. BUG_ON(hwgroup->drive != NULL);
  260. hwgroup->hwif = g;
  261. }
  262. BUG_ON(hwgroup->hwif == hwif);
  263. }
  264. spin_unlock_irq(&ide_lock);
  265. }
  266. /* Called with ide_lock held. */
  267. static void __ide_port_unregister_devices(ide_hwif_t *hwif)
  268. {
  269. int i;
  270. for (i = 0; i < MAX_DRIVES; i++) {
  271. ide_drive_t *drive = &hwif->drives[i];
  272. if (drive->present) {
  273. spin_unlock_irq(&ide_lock);
  274. device_unregister(&drive->gendev);
  275. wait_for_completion(&drive->gendev_rel_comp);
  276. spin_lock_irq(&ide_lock);
  277. }
  278. }
  279. }
  280. void ide_port_unregister_devices(ide_hwif_t *hwif)
  281. {
  282. mutex_lock(&ide_cfg_mtx);
  283. spin_lock_irq(&ide_lock);
  284. __ide_port_unregister_devices(hwif);
  285. hwif->present = 0;
  286. ide_port_init_devices_data(hwif);
  287. spin_unlock_irq(&ide_lock);
  288. mutex_unlock(&ide_cfg_mtx);
  289. }
  290. EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
  291. /**
  292. * ide_unregister - free an IDE interface
  293. * @index: index of interface (will change soon to a pointer)
  294. *
  295. * Perform the final unregister of an IDE interface. At the moment
  296. * we don't refcount interfaces so this will also get split up.
  297. *
  298. * Locking:
  299. * The caller must not hold the IDE locks
  300. * The drive present/vanishing is not yet properly locked
  301. * Take care with the callbacks. These have been split to avoid
  302. * deadlocking the IDE layer. The shutdown callback is called
  303. * before we take the lock and free resources. It is up to the
  304. * caller to be sure there is no pending I/O here, and that
  305. * the interface will not be reopened (present/vanishing locking
  306. * isn't yet done BTW). After we commit to the final kill we
  307. * call the cleanup callback with the ide locks held.
  308. *
  309. * Unregister restores the hwif structures to the default state.
  310. * This is raving bonkers.
  311. */
  312. void ide_unregister(unsigned int index)
  313. {
  314. ide_hwif_t *hwif, *g;
  315. ide_hwgroup_t *hwgroup;
  316. int irq_count = 0;
  317. BUG_ON(index >= MAX_HWIFS);
  318. BUG_ON(in_interrupt());
  319. BUG_ON(irqs_disabled());
  320. mutex_lock(&ide_cfg_mtx);
  321. spin_lock_irq(&ide_lock);
  322. hwif = &ide_hwifs[index];
  323. if (!hwif->present)
  324. goto abort;
  325. __ide_port_unregister_devices(hwif);
  326. hwif->present = 0;
  327. spin_unlock_irq(&ide_lock);
  328. ide_proc_unregister_port(hwif);
  329. hwgroup = hwif->hwgroup;
  330. /*
  331. * free the irq if we were the only hwif using it
  332. */
  333. g = hwgroup->hwif;
  334. do {
  335. if (g->irq == hwif->irq)
  336. ++irq_count;
  337. g = g->next;
  338. } while (g != hwgroup->hwif);
  339. if (irq_count == 1)
  340. free_irq(hwif->irq, hwgroup);
  341. ide_remove_port_from_hwgroup(hwif);
  342. device_unregister(hwif->portdev);
  343. device_unregister(&hwif->gendev);
  344. wait_for_completion(&hwif->gendev_rel_comp);
  345. /*
  346. * Remove us from the kernel's knowledge
  347. */
  348. blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
  349. kfree(hwif->sg_table);
  350. unregister_blkdev(hwif->major, hwif->name);
  351. spin_lock_irq(&ide_lock);
  352. if (hwif->dma_base)
  353. ide_release_dma_engine(hwif);
  354. /* restore hwif data to pristine status */
  355. ide_init_port_data(hwif, index);
  356. abort:
  357. spin_unlock_irq(&ide_lock);
  358. mutex_unlock(&ide_cfg_mtx);
  359. }
  360. EXPORT_SYMBOL(ide_unregister);
  361. void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
  362. {
  363. memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
  364. hwif->irq = hw->irq;
  365. hwif->chipset = hw->chipset;
  366. hwif->gendev.parent = hw->dev;
  367. hwif->ack_intr = hw->ack_intr;
  368. }
  369. EXPORT_SYMBOL_GPL(ide_init_port_hw);
  370. /*
  371. * Locks for IDE setting functionality
  372. */
  373. DEFINE_MUTEX(ide_setting_mtx);
  374. EXPORT_SYMBOL_GPL(ide_setting_mtx);
  375. /**
  376. * ide_spin_wait_hwgroup - wait for group
  377. * @drive: drive in the group
  378. *
  379. * Wait for an IDE device group to go non busy and then return
  380. * holding the ide_lock which guards the hwgroup->busy status
  381. * and right to use it.
  382. */
  383. int ide_spin_wait_hwgroup (ide_drive_t *drive)
  384. {
  385. ide_hwgroup_t *hwgroup = HWGROUP(drive);
  386. unsigned long timeout = jiffies + (3 * HZ);
  387. spin_lock_irq(&ide_lock);
  388. while (hwgroup->busy) {
  389. unsigned long lflags;
  390. spin_unlock_irq(&ide_lock);
  391. local_irq_set(lflags);
  392. if (time_after(jiffies, timeout)) {
  393. local_irq_restore(lflags);
  394. printk(KERN_ERR "%s: channel busy\n", drive->name);
  395. return -EBUSY;
  396. }
  397. local_irq_restore(lflags);
  398. spin_lock_irq(&ide_lock);
  399. }
  400. return 0;
  401. }
  402. EXPORT_SYMBOL(ide_spin_wait_hwgroup);
  403. int set_io_32bit(ide_drive_t *drive, int arg)
  404. {
  405. if (drive->no_io_32bit)
  406. return -EPERM;
  407. if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
  408. return -EINVAL;
  409. if (ide_spin_wait_hwgroup(drive))
  410. return -EBUSY;
  411. drive->io_32bit = arg;
  412. spin_unlock_irq(&ide_lock);
  413. return 0;
  414. }
  415. static int set_ksettings(ide_drive_t *drive, int arg)
  416. {
  417. if (arg < 0 || arg > 1)
  418. return -EINVAL;
  419. if (ide_spin_wait_hwgroup(drive))
  420. return -EBUSY;
  421. drive->keep_settings = arg;
  422. spin_unlock_irq(&ide_lock);
  423. return 0;
  424. }
  425. int set_using_dma(ide_drive_t *drive, int arg)
  426. {
  427. #ifdef CONFIG_BLK_DEV_IDEDMA
  428. ide_hwif_t *hwif = drive->hwif;
  429. int err = -EPERM;
  430. if (arg < 0 || arg > 1)
  431. return -EINVAL;
  432. if (!drive->id || !(drive->id->capability & 1))
  433. goto out;
  434. if (hwif->dma_host_set == NULL)
  435. goto out;
  436. err = -EBUSY;
  437. if (ide_spin_wait_hwgroup(drive))
  438. goto out;
  439. /*
  440. * set ->busy flag, unlock and let it ride
  441. */
  442. hwif->hwgroup->busy = 1;
  443. spin_unlock_irq(&ide_lock);
  444. err = 0;
  445. if (arg) {
  446. if (ide_set_dma(drive))
  447. err = -EIO;
  448. } else
  449. ide_dma_off(drive);
  450. /*
  451. * lock, clear ->busy flag and unlock before leaving
  452. */
  453. spin_lock_irq(&ide_lock);
  454. hwif->hwgroup->busy = 0;
  455. spin_unlock_irq(&ide_lock);
  456. out:
  457. return err;
  458. #else
  459. if (arg < 0 || arg > 1)
  460. return -EINVAL;
  461. return -EPERM;
  462. #endif
  463. }
  464. int set_pio_mode(ide_drive_t *drive, int arg)
  465. {
  466. struct request rq;
  467. ide_hwif_t *hwif = drive->hwif;
  468. const struct ide_port_ops *port_ops = hwif->port_ops;
  469. if (arg < 0 || arg > 255)
  470. return -EINVAL;
  471. if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
  472. (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
  473. return -ENOSYS;
  474. if (drive->special.b.set_tune)
  475. return -EBUSY;
  476. ide_init_drive_cmd(&rq);
  477. rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
  478. drive->tune_req = (u8) arg;
  479. drive->special.b.set_tune = 1;
  480. (void) ide_do_drive_cmd(drive, &rq, ide_wait);
  481. return 0;
  482. }
  483. static int set_unmaskirq(ide_drive_t *drive, int arg)
  484. {
  485. if (drive->no_unmask)
  486. return -EPERM;
  487. if (arg < 0 || arg > 1)
  488. return -EINVAL;
  489. if (ide_spin_wait_hwgroup(drive))
  490. return -EBUSY;
  491. drive->unmask = arg;
  492. spin_unlock_irq(&ide_lock);
  493. return 0;
  494. }
  495. /**
  496. * system_bus_clock - clock guess
  497. *
  498. * External version of the bus clock guess used by very old IDE drivers
  499. * for things like VLB timings. Should not be used.
  500. */
  501. int system_bus_clock (void)
  502. {
  503. return system_bus_speed;
  504. }
  505. EXPORT_SYMBOL(system_bus_clock);
  506. static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
  507. {
  508. ide_drive_t *drive = dev->driver_data;
  509. ide_hwif_t *hwif = HWIF(drive);
  510. struct request rq;
  511. struct request_pm_state rqpm;
  512. ide_task_t args;
  513. int ret;
  514. /* Call ACPI _GTM only once */
  515. if (!(drive->dn % 2))
  516. ide_acpi_get_timing(hwif);
  517. memset(&rq, 0, sizeof(rq));
  518. memset(&rqpm, 0, sizeof(rqpm));
  519. memset(&args, 0, sizeof(args));
  520. rq.cmd_type = REQ_TYPE_PM_SUSPEND;
  521. rq.special = &args;
  522. rq.data = &rqpm;
  523. rqpm.pm_step = ide_pm_state_start_suspend;
  524. if (mesg.event == PM_EVENT_PRETHAW)
  525. mesg.event = PM_EVENT_FREEZE;
  526. rqpm.pm_state = mesg.event;
  527. ret = ide_do_drive_cmd(drive, &rq, ide_wait);
  528. /* only call ACPI _PS3 after both drivers are suspended */
  529. if (!ret && (((drive->dn % 2) && hwif->drives[0].present
  530. && hwif->drives[1].present)
  531. || !hwif->drives[0].present
  532. || !hwif->drives[1].present))
  533. ide_acpi_set_state(hwif, 0);
  534. return ret;
  535. }
  536. static int generic_ide_resume(struct device *dev)
  537. {
  538. ide_drive_t *drive = dev->driver_data;
  539. ide_hwif_t *hwif = HWIF(drive);
  540. struct request rq;
  541. struct request_pm_state rqpm;
  542. ide_task_t args;
  543. int err;
  544. /* Call ACPI _STM only once */
  545. if (!(drive->dn % 2)) {
  546. ide_acpi_set_state(hwif, 1);
  547. ide_acpi_push_timing(hwif);
  548. }
  549. ide_acpi_exec_tfs(drive);
  550. memset(&rq, 0, sizeof(rq));
  551. memset(&rqpm, 0, sizeof(rqpm));
  552. memset(&args, 0, sizeof(args));
  553. rq.cmd_type = REQ_TYPE_PM_RESUME;
  554. rq.special = &args;
  555. rq.data = &rqpm;
  556. rqpm.pm_step = ide_pm_state_start_resume;
  557. rqpm.pm_state = PM_EVENT_ON;
  558. err = ide_do_drive_cmd(drive, &rq, ide_head_wait);
  559. if (err == 0 && dev->driver) {
  560. ide_driver_t *drv = to_ide_driver(dev->driver);
  561. if (drv->resume)
  562. drv->resume(drive);
  563. }
  564. return err;
  565. }
  566. int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
  567. unsigned int cmd, unsigned long arg)
  568. {
  569. unsigned long flags;
  570. ide_driver_t *drv;
  571. void __user *p = (void __user *)arg;
  572. int err = 0, (*setfunc)(ide_drive_t *, int);
  573. u8 *val;
  574. switch (cmd) {
  575. case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val;
  576. case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
  577. case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val;
  578. case HDIO_GET_DMA: val = &drive->using_dma; goto read_val;
  579. case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val;
  580. case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val;
  581. case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val;
  582. case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val;
  583. case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val;
  584. }
  585. switch (cmd) {
  586. case HDIO_OBSOLETE_IDENTITY:
  587. case HDIO_GET_IDENTITY:
  588. if (bdev != bdev->bd_contains)
  589. return -EINVAL;
  590. if (drive->id_read == 0)
  591. return -ENOMSG;
  592. if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
  593. return -EFAULT;
  594. return 0;
  595. case HDIO_GET_NICE:
  596. return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
  597. drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
  598. drive->nice1 << IDE_NICE_1,
  599. (long __user *) arg);
  600. #ifdef CONFIG_IDE_TASK_IOCTL
  601. case HDIO_DRIVE_TASKFILE:
  602. if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
  603. return -EACCES;
  604. switch(drive->media) {
  605. case ide_disk:
  606. return ide_taskfile_ioctl(drive, cmd, arg);
  607. default:
  608. return -ENOMSG;
  609. }
  610. #endif /* CONFIG_IDE_TASK_IOCTL */
  611. case HDIO_DRIVE_CMD:
  612. if (!capable(CAP_SYS_RAWIO))
  613. return -EACCES;
  614. return ide_cmd_ioctl(drive, cmd, arg);
  615. case HDIO_DRIVE_TASK:
  616. if (!capable(CAP_SYS_RAWIO))
  617. return -EACCES;
  618. return ide_task_ioctl(drive, cmd, arg);
  619. case HDIO_SET_NICE:
  620. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  621. if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
  622. return -EPERM;
  623. drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
  624. drv = *(ide_driver_t **)bdev->bd_disk->private_data;
  625. if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
  626. drive->dsc_overlap = 0;
  627. return -EPERM;
  628. }
  629. drive->nice1 = (arg >> IDE_NICE_1) & 1;
  630. return 0;
  631. case HDIO_DRIVE_RESET:
  632. if (!capable(CAP_SYS_ADMIN))
  633. return -EACCES;
  634. /*
  635. * Abort the current command on the
  636. * group if there is one, taking
  637. * care not to allow anything else
  638. * to be queued and to die on the
  639. * spot if we miss one somehow
  640. */
  641. spin_lock_irqsave(&ide_lock, flags);
  642. if (HWGROUP(drive)->resetting) {
  643. spin_unlock_irqrestore(&ide_lock, flags);
  644. return -EBUSY;
  645. }
  646. ide_abort(drive, "drive reset");
  647. BUG_ON(HWGROUP(drive)->handler);
  648. /* Ensure nothing gets queued after we
  649. drop the lock. Reset will clear the busy */
  650. HWGROUP(drive)->busy = 1;
  651. spin_unlock_irqrestore(&ide_lock, flags);
  652. (void) ide_do_reset(drive);
  653. return 0;
  654. case HDIO_GET_BUSSTATE:
  655. if (!capable(CAP_SYS_ADMIN))
  656. return -EACCES;
  657. if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
  658. return -EFAULT;
  659. return 0;
  660. case HDIO_SET_BUSSTATE:
  661. if (!capable(CAP_SYS_ADMIN))
  662. return -EACCES;
  663. return -EOPNOTSUPP;
  664. default:
  665. return -EINVAL;
  666. }
  667. read_val:
  668. mutex_lock(&ide_setting_mtx);
  669. spin_lock_irqsave(&ide_lock, flags);
  670. err = *val;
  671. spin_unlock_irqrestore(&ide_lock, flags);
  672. mutex_unlock(&ide_setting_mtx);
  673. return err >= 0 ? put_user(err, (long __user *)arg) : err;
  674. set_val:
  675. if (bdev != bdev->bd_contains)
  676. err = -EINVAL;
  677. else {
  678. if (!capable(CAP_SYS_ADMIN))
  679. err = -EACCES;
  680. else {
  681. mutex_lock(&ide_setting_mtx);
  682. err = setfunc(drive, arg);
  683. mutex_unlock(&ide_setting_mtx);
  684. }
  685. }
  686. return err;
  687. }
  688. EXPORT_SYMBOL(generic_ide_ioctl);
  689. /*
  690. * stridx() returns the offset of c within s,
  691. * or -1 if c is '\0' or not found within s.
  692. */
  693. static int __init stridx (const char *s, char c)
  694. {
  695. char *i = strchr(s, c);
  696. return (i && c) ? i - s : -1;
  697. }
  698. /*
  699. * match_parm() does parsing for ide_setup():
  700. *
  701. * 1. the first char of s must be '='.
  702. * 2. if the remainder matches one of the supplied keywords,
  703. * the index (1 based) of the keyword is negated and returned.
  704. * 3. if the remainder is a series of no more than max_vals numbers
  705. * separated by commas, the numbers are saved in vals[] and a
  706. * count of how many were saved is returned. Base10 is assumed,
  707. * and base16 is allowed when prefixed with "0x".
  708. * 4. otherwise, zero is returned.
  709. */
  710. static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
  711. {
  712. static const char *decimal = "0123456789";
  713. static const char *hex = "0123456789abcdef";
  714. int i, n;
  715. if (*s++ == '=') {
  716. /*
  717. * Try matching against the supplied keywords,
  718. * and return -(index+1) if we match one
  719. */
  720. if (keywords != NULL) {
  721. for (i = 0; *keywords != NULL; ++i) {
  722. if (!strcmp(s, *keywords++))
  723. return -(i+1);
  724. }
  725. }
  726. /*
  727. * Look for a series of no more than "max_vals"
  728. * numeric values separated by commas, in base10,
  729. * or base16 when prefixed with "0x".
  730. * Return a count of how many were found.
  731. */
  732. for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
  733. vals[n] = i;
  734. while ((i = stridx(decimal, *++s)) >= 0)
  735. vals[n] = (vals[n] * 10) + i;
  736. if (*s == 'x' && !vals[n]) {
  737. while ((i = stridx(hex, *++s)) >= 0)
  738. vals[n] = (vals[n] * 0x10) + i;
  739. }
  740. if (++n == max_vals)
  741. break;
  742. if (*s == ',' || *s == ';')
  743. ++s;
  744. }
  745. if (!*s)
  746. return n;
  747. }
  748. return 0; /* zero = nothing matched */
  749. }
  750. extern int probe_ali14xx;
  751. extern int probe_umc8672;
  752. extern int probe_dtc2278;
  753. extern int probe_ht6560b;
  754. extern int probe_qd65xx;
  755. extern int cmd640_vlb;
  756. extern int probe_4drives;
  757. static int __initdata is_chipset_set;
  758. /*
  759. * ide_setup() gets called VERY EARLY during initialization,
  760. * to handle kernel "command line" strings beginning with "hdx=" or "ide".
  761. *
  762. * Remember to update Documentation/ide/ide.txt if you change something here.
  763. */
  764. static int __init ide_setup(char *s)
  765. {
  766. int i, vals[3];
  767. ide_hwif_t *hwif;
  768. ide_drive_t *drive;
  769. unsigned int hw, unit;
  770. const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
  771. const char max_hwif = '0' + (MAX_HWIFS - 1);
  772. if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
  773. return 0; /* driver and not us */
  774. if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
  775. return 0;
  776. printk(KERN_INFO "ide_setup: %s", s);
  777. init_ide_data ();
  778. #ifdef CONFIG_BLK_DEV_IDEDOUBLER
  779. if (!strcmp(s, "ide=doubler")) {
  780. extern int ide_doubler;
  781. printk(" : Enabled support for IDE doublers\n");
  782. ide_doubler = 1;
  783. return 1;
  784. }
  785. #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
  786. if (!strcmp(s, "ide=nodma")) {
  787. printk(" : Prevented DMA\n");
  788. noautodma = 1;
  789. goto obsolete_option;
  790. }
  791. #ifdef CONFIG_BLK_DEV_IDEACPI
  792. if (!strcmp(s, "ide=noacpi")) {
  793. //printk(" : Disable IDE ACPI support.\n");
  794. ide_noacpi = 1;
  795. return 1;
  796. }
  797. if (!strcmp(s, "ide=acpigtf")) {
  798. //printk(" : Enable IDE ACPI _GTF support.\n");
  799. ide_noacpitfs = 0;
  800. return 1;
  801. }
  802. if (!strcmp(s, "ide=acpionboot")) {
  803. //printk(" : Call IDE ACPI methods on boot.\n");
  804. ide_noacpionboot = 0;
  805. return 1;
  806. }
  807. #endif /* CONFIG_BLK_DEV_IDEACPI */
  808. /*
  809. * Look for drive options: "hdx="
  810. */
  811. if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
  812. const char *hd_words[] = {
  813. "none", "noprobe", "nowerr", "cdrom", "nodma",
  814. "autotune", "noautotune", "-8", "-9", "-10",
  815. "noflush", "remap", "remap63", "scsi", NULL };
  816. unit = s[2] - 'a';
  817. hw = unit / MAX_DRIVES;
  818. unit = unit % MAX_DRIVES;
  819. hwif = &ide_hwifs[hw];
  820. drive = &hwif->drives[unit];
  821. if (strncmp(s + 4, "ide-", 4) == 0) {
  822. strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
  823. goto obsolete_option;
  824. }
  825. switch (match_parm(&s[3], hd_words, vals, 3)) {
  826. case -1: /* "none" */
  827. case -2: /* "noprobe" */
  828. drive->noprobe = 1;
  829. goto done;
  830. case -3: /* "nowerr" */
  831. drive->bad_wstat = BAD_R_STAT;
  832. goto done;
  833. case -4: /* "cdrom" */
  834. drive->present = 1;
  835. drive->media = ide_cdrom;
  836. /* an ATAPI device ignores DRDY */
  837. drive->ready_stat = 0;
  838. goto done;
  839. case -5: /* nodma */
  840. drive->nodma = 1;
  841. goto done;
  842. case -6: /* "autotune" */
  843. drive->autotune = IDE_TUNE_AUTO;
  844. goto obsolete_option;
  845. case -7: /* "noautotune" */
  846. drive->autotune = IDE_TUNE_NOAUTO;
  847. goto obsolete_option;
  848. case -11: /* noflush */
  849. drive->noflush = 1;
  850. goto done;
  851. case -12: /* "remap" */
  852. drive->remap_0_to_1 = 1;
  853. goto obsolete_option;
  854. case -13: /* "remap63" */
  855. drive->sect0 = 63;
  856. goto obsolete_option;
  857. case -14: /* "scsi" */
  858. drive->scsi = 1;
  859. goto obsolete_option;
  860. case 3: /* cyl,head,sect */
  861. drive->media = ide_disk;
  862. drive->ready_stat = READY_STAT;
  863. drive->cyl = drive->bios_cyl = vals[0];
  864. drive->head = drive->bios_head = vals[1];
  865. drive->sect = drive->bios_sect = vals[2];
  866. drive->present = 1;
  867. drive->forced_geom = 1;
  868. goto done;
  869. default:
  870. goto bad_option;
  871. }
  872. }
  873. if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
  874. goto bad_option;
  875. /*
  876. * Look for bus speed option: "idebus="
  877. */
  878. if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
  879. if (match_parm(&s[6], NULL, vals, 1) != 1)
  880. goto bad_option;
  881. if (vals[0] >= 20 && vals[0] <= 66) {
  882. idebus_parameter = vals[0];
  883. } else
  884. printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
  885. goto done;
  886. }
  887. /*
  888. * Look for interface options: "idex="
  889. */
  890. if (s[3] >= '0' && s[3] <= max_hwif) {
  891. /*
  892. * Be VERY CAREFUL changing this: note hardcoded indexes below
  893. * (-8, -9, -10) are reserved to ease the hardcoding.
  894. */
  895. static const char *ide_words[] = {
  896. "minus1", "serialize", "minus3", "minus4",
  897. "reset", "minus6", "ata66", "minus8", "minus9",
  898. "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
  899. "dtc2278", "umc8672", "ali14xx", NULL };
  900. hw = s[3] - '0';
  901. hwif = &ide_hwifs[hw];
  902. i = match_parm(&s[4], ide_words, vals, 3);
  903. /*
  904. * Cryptic check to ensure chipset not already set for hwif.
  905. * Note: we can't depend on hwif->chipset here.
  906. */
  907. if (i >= -18 && i <= -11) {
  908. /* chipset already specified */
  909. if (is_chipset_set)
  910. goto bad_option;
  911. /* these drivers are for "ide0=" only */
  912. if (hw != 0)
  913. goto bad_hwif;
  914. is_chipset_set = 1;
  915. printk("\n");
  916. }
  917. switch (i) {
  918. #ifdef CONFIG_BLK_DEV_ALI14XX
  919. case -17: /* "ali14xx" */
  920. probe_ali14xx = 1;
  921. goto obsolete_option;
  922. #endif
  923. #ifdef CONFIG_BLK_DEV_UMC8672
  924. case -16: /* "umc8672" */
  925. probe_umc8672 = 1;
  926. goto obsolete_option;
  927. #endif
  928. #ifdef CONFIG_BLK_DEV_DTC2278
  929. case -15: /* "dtc2278" */
  930. probe_dtc2278 = 1;
  931. goto obsolete_option;
  932. #endif
  933. #ifdef CONFIG_BLK_DEV_CMD640
  934. case -14: /* "cmd640_vlb" */
  935. cmd640_vlb = 1;
  936. goto obsolete_option;
  937. #endif
  938. #ifdef CONFIG_BLK_DEV_HT6560B
  939. case -13: /* "ht6560b" */
  940. probe_ht6560b = 1;
  941. goto obsolete_option;
  942. #endif
  943. #ifdef CONFIG_BLK_DEV_QD65XX
  944. case -12: /* "qd65xx" */
  945. probe_qd65xx = 1;
  946. goto obsolete_option;
  947. #endif
  948. #ifdef CONFIG_BLK_DEV_4DRIVES
  949. case -11: /* "four" drives on one set of ports */
  950. probe_4drives = 1;
  951. goto obsolete_option;
  952. #endif
  953. case -10: /* minus10 */
  954. case -9: /* minus9 */
  955. case -8: /* minus8 */
  956. case -6:
  957. case -4:
  958. case -3:
  959. goto bad_option;
  960. case -7: /* ata66 */
  961. #ifdef CONFIG_BLK_DEV_IDEPCI
  962. /*
  963. * Use ATA_CBL_PATA40_SHORT so drive side
  964. * cable detection is also overriden.
  965. */
  966. hwif->cbl = ATA_CBL_PATA40_SHORT;
  967. goto obsolete_option;
  968. #else
  969. goto bad_hwif;
  970. #endif
  971. case -5: /* "reset" */
  972. hwif->reset = 1;
  973. goto obsolete_option;
  974. case -2: /* "serialize" */
  975. hwif->mate = &ide_hwifs[hw^1];
  976. hwif->mate->mate = hwif;
  977. hwif->serialized = hwif->mate->serialized = 1;
  978. goto obsolete_option;
  979. case -1:
  980. case 0:
  981. case 1:
  982. case 2:
  983. case 3:
  984. goto bad_option;
  985. default:
  986. printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
  987. return 1;
  988. }
  989. }
  990. bad_option:
  991. printk(" -- BAD OPTION\n");
  992. return 1;
  993. obsolete_option:
  994. printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
  995. return 1;
  996. bad_hwif:
  997. printk("-- NOT SUPPORTED ON ide%d", hw);
  998. done:
  999. printk("\n");
  1000. return 1;
  1001. }
  1002. EXPORT_SYMBOL(ide_lock);
  1003. static int ide_bus_match(struct device *dev, struct device_driver *drv)
  1004. {
  1005. return 1;
  1006. }
  1007. static char *media_string(ide_drive_t *drive)
  1008. {
  1009. switch (drive->media) {
  1010. case ide_disk:
  1011. return "disk";
  1012. case ide_cdrom:
  1013. return "cdrom";
  1014. case ide_tape:
  1015. return "tape";
  1016. case ide_floppy:
  1017. return "floppy";
  1018. case ide_optical:
  1019. return "optical";
  1020. default:
  1021. return "UNKNOWN";
  1022. }
  1023. }
  1024. static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
  1025. {
  1026. ide_drive_t *drive = to_ide_device(dev);
  1027. return sprintf(buf, "%s\n", media_string(drive));
  1028. }
  1029. static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
  1030. {
  1031. ide_drive_t *drive = to_ide_device(dev);
  1032. return sprintf(buf, "%s\n", drive->name);
  1033. }
  1034. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
  1035. {
  1036. ide_drive_t *drive = to_ide_device(dev);
  1037. return sprintf(buf, "ide:m-%s\n", media_string(drive));
  1038. }
  1039. static ssize_t model_show(struct device *dev, struct device_attribute *attr,
  1040. char *buf)
  1041. {
  1042. ide_drive_t *drive = to_ide_device(dev);
  1043. return sprintf(buf, "%s\n", drive->id->model);
  1044. }
  1045. static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
  1046. char *buf)
  1047. {
  1048. ide_drive_t *drive = to_ide_device(dev);
  1049. return sprintf(buf, "%s\n", drive->id->fw_rev);
  1050. }
  1051. static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
  1052. char *buf)
  1053. {
  1054. ide_drive_t *drive = to_ide_device(dev);
  1055. return sprintf(buf, "%s\n", drive->id->serial_no);
  1056. }
  1057. static struct device_attribute ide_dev_attrs[] = {
  1058. __ATTR_RO(media),
  1059. __ATTR_RO(drivename),
  1060. __ATTR_RO(modalias),
  1061. __ATTR_RO(model),
  1062. __ATTR_RO(firmware),
  1063. __ATTR(serial, 0400, serial_show, NULL),
  1064. __ATTR_NULL
  1065. };
  1066. static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
  1067. {
  1068. ide_drive_t *drive = to_ide_device(dev);
  1069. add_uevent_var(env, "MEDIA=%s", media_string(drive));
  1070. add_uevent_var(env, "DRIVENAME=%s", drive->name);
  1071. add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive));
  1072. return 0;
  1073. }
  1074. static int generic_ide_probe(struct device *dev)
  1075. {
  1076. ide_drive_t *drive = to_ide_device(dev);
  1077. ide_driver_t *drv = to_ide_driver(dev->driver);
  1078. return drv->probe ? drv->probe(drive) : -ENODEV;
  1079. }
  1080. static int generic_ide_remove(struct device *dev)
  1081. {
  1082. ide_drive_t *drive = to_ide_device(dev);
  1083. ide_driver_t *drv = to_ide_driver(dev->driver);
  1084. if (drv->remove)
  1085. drv->remove(drive);
  1086. return 0;
  1087. }
  1088. static void generic_ide_shutdown(struct device *dev)
  1089. {
  1090. ide_drive_t *drive = to_ide_device(dev);
  1091. ide_driver_t *drv = to_ide_driver(dev->driver);
  1092. if (dev->driver && drv->shutdown)
  1093. drv->shutdown(drive);
  1094. }
  1095. struct bus_type ide_bus_type = {
  1096. .name = "ide",
  1097. .match = ide_bus_match,
  1098. .uevent = ide_uevent,
  1099. .probe = generic_ide_probe,
  1100. .remove = generic_ide_remove,
  1101. .shutdown = generic_ide_shutdown,
  1102. .dev_attrs = ide_dev_attrs,
  1103. .suspend = generic_ide_suspend,
  1104. .resume = generic_ide_resume,
  1105. };
  1106. EXPORT_SYMBOL_GPL(ide_bus_type);
  1107. static void ide_port_class_release(struct device *portdev)
  1108. {
  1109. ide_hwif_t *hwif = dev_get_drvdata(portdev);
  1110. put_device(&hwif->gendev);
  1111. }
  1112. /*
  1113. * This is gets invoked once during initialization, to set *everything* up
  1114. */
  1115. static int __init ide_init(void)
  1116. {
  1117. int ret;
  1118. printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
  1119. system_bus_speed = ide_system_bus_speed();
  1120. printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
  1121. "for PIO modes%s\n", system_bus_speed,
  1122. idebus_parameter ? "" : "; override with idebus=xx");
  1123. ret = bus_register(&ide_bus_type);
  1124. if (ret < 0) {
  1125. printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
  1126. return ret;
  1127. }
  1128. ide_port_class = class_create(THIS_MODULE, "ide_port");
  1129. if (IS_ERR(ide_port_class)) {
  1130. ret = PTR_ERR(ide_port_class);
  1131. goto out_port_class;
  1132. }
  1133. ide_port_class->dev_release = ide_port_class_release;
  1134. init_ide_data();
  1135. proc_ide_create();
  1136. return 0;
  1137. out_port_class:
  1138. bus_unregister(&ide_bus_type);
  1139. return ret;
  1140. }
  1141. #ifdef MODULE
  1142. static char *options = NULL;
  1143. module_param(options, charp, 0);
  1144. MODULE_LICENSE("GPL");
  1145. static void __init parse_options (char *line)
  1146. {
  1147. char *next = line;
  1148. if (line == NULL || !*line)
  1149. return;
  1150. while ((line = next) != NULL) {
  1151. if ((next = strchr(line,' ')) != NULL)
  1152. *next++ = 0;
  1153. if (!ide_setup(line))
  1154. printk (KERN_INFO "Unknown option '%s'\n", line);
  1155. }
  1156. }
  1157. int __init init_module (void)
  1158. {
  1159. parse_options(options);
  1160. return ide_init();
  1161. }
  1162. void __exit cleanup_module (void)
  1163. {
  1164. int index;
  1165. for (index = 0; index < MAX_HWIFS; ++index)
  1166. ide_unregister(index);
  1167. proc_ide_destroy();
  1168. class_destroy(ide_port_class);
  1169. bus_unregister(&ide_bus_type);
  1170. }
  1171. #else /* !MODULE */
  1172. __setup("", ide_setup);
  1173. module_init(ide_init);
  1174. #endif /* MODULE */