ide.c 35 KB

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