PageRenderTime 65ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/ide/ide.c

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