ide.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682
  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. static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
  75. IDE2_MAJOR, IDE3_MAJOR,
  76. IDE4_MAJOR, IDE5_MAJOR,
  77. IDE6_MAJOR, IDE7_MAJOR,
  78. IDE8_MAJOR, IDE9_MAJOR };
  79. static int idebus_parameter; /* holds the "idebus=" parameter */
  80. static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */
  81. DEFINE_MUTEX(ide_cfg_mtx);
  82. __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
  83. #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
  84. int ide_scan_direction; /* THIS was formerly 2.2.x pci=reverse */
  85. #endif
  86. int noautodma = 0;
  87. #ifdef CONFIG_BLK_DEV_IDEACPI
  88. int ide_noacpi = 0;
  89. int ide_noacpitfs = 1;
  90. int ide_noacpionboot = 1;
  91. #endif
  92. /*
  93. * This is declared extern in ide.h, for access by other IDE modules:
  94. */
  95. ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
  96. EXPORT_SYMBOL(ide_hwifs);
  97. /*
  98. * Do not even *think* about calling this!
  99. */
  100. void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
  101. {
  102. unsigned int unit;
  103. /* bulk initialize hwif & drive info with zeros */
  104. memset(hwif, 0, sizeof(ide_hwif_t));
  105. /* fill in any non-zero initial values */
  106. hwif->index = index;
  107. hwif->major = ide_hwif_to_major[index];
  108. hwif->name[0] = 'i';
  109. hwif->name[1] = 'd';
  110. hwif->name[2] = 'e';
  111. hwif->name[3] = '0' + index;
  112. hwif->bus_state = BUSSTATE_ON;
  113. init_completion(&hwif->gendev_rel_comp);
  114. default_hwif_iops(hwif);
  115. default_hwif_transport(hwif);
  116. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  117. ide_drive_t *drive = &hwif->drives[unit];
  118. drive->media = ide_disk;
  119. drive->select.all = (unit<<4)|0xa0;
  120. drive->hwif = hwif;
  121. drive->ctl = 0x08;
  122. drive->ready_stat = READY_STAT;
  123. drive->bad_wstat = BAD_W_STAT;
  124. drive->special.b.recalibrate = 1;
  125. drive->special.b.set_geometry = 1;
  126. drive->name[0] = 'h';
  127. drive->name[1] = 'd';
  128. drive->name[2] = 'a' + (index * MAX_DRIVES) + unit;
  129. drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
  130. drive->using_dma = 0;
  131. drive->vdma = 0;
  132. INIT_LIST_HEAD(&drive->list);
  133. init_completion(&drive->gendev_rel_comp);
  134. }
  135. }
  136. EXPORT_SYMBOL_GPL(ide_init_port_data);
  137. static void init_hwif_default(ide_hwif_t *hwif, unsigned int index)
  138. {
  139. hw_regs_t hw;
  140. memset(&hw, 0, sizeof(hw_regs_t));
  141. ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
  142. memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
  143. hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
  144. #ifdef CONFIG_BLK_DEV_HD
  145. if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)
  146. hwif->noprobe = 1; /* may be overridden by ide_setup() */
  147. #endif
  148. }
  149. /*
  150. * init_ide_data() sets reasonable default values into all fields
  151. * of all instances of the hwifs and drives, but only on the first call.
  152. * Subsequent calls have no effect (they don't wipe out anything).
  153. *
  154. * This routine is normally called at driver initialization time,
  155. * but may also be called MUCH earlier during kernel "command-line"
  156. * parameter processing. As such, we cannot depend on any other parts
  157. * of the kernel (such as memory allocation) to be functioning yet.
  158. *
  159. * This is too bad, as otherwise we could dynamically allocate the
  160. * ide_drive_t structs as needed, rather than always consuming memory
  161. * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
  162. *
  163. * FIXME: We should stuff the setup data into __init and copy the
  164. * relevant hwifs/allocate them properly during boot.
  165. */
  166. #define MAGIC_COOKIE 0x12345678
  167. static void __init init_ide_data (void)
  168. {
  169. ide_hwif_t *hwif;
  170. unsigned int index;
  171. static unsigned long magic_cookie = MAGIC_COOKIE;
  172. if (magic_cookie != MAGIC_COOKIE)
  173. return; /* already initialized */
  174. magic_cookie = 0;
  175. /* Initialise all interface structures */
  176. for (index = 0; index < MAX_HWIFS; ++index) {
  177. hwif = &ide_hwifs[index];
  178. ide_init_port_data(hwif, index);
  179. init_hwif_default(hwif, index);
  180. #if !defined(CONFIG_PPC32) || !defined(CONFIG_PCI)
  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->io_ports[IDE_DATA_OFFSET] == 0)
  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. /**
  312. * ide_hwif_restore - restore hwif to template
  313. * @hwif: hwif to update
  314. * @tmp_hwif: template
  315. *
  316. * Restore hwif to a previous state by copying most settings
  317. * from the template.
  318. */
  319. static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
  320. {
  321. hwif->hwgroup = tmp_hwif->hwgroup;
  322. hwif->gendev.parent = tmp_hwif->gendev.parent;
  323. hwif->proc = tmp_hwif->proc;
  324. hwif->major = tmp_hwif->major;
  325. hwif->straight8 = tmp_hwif->straight8;
  326. hwif->bus_state = tmp_hwif->bus_state;
  327. hwif->host_flags = tmp_hwif->host_flags;
  328. hwif->pio_mask = tmp_hwif->pio_mask;
  329. hwif->ultra_mask = tmp_hwif->ultra_mask;
  330. hwif->mwdma_mask = tmp_hwif->mwdma_mask;
  331. hwif->swdma_mask = tmp_hwif->swdma_mask;
  332. hwif->cbl = tmp_hwif->cbl;
  333. hwif->chipset = tmp_hwif->chipset;
  334. hwif->hold = tmp_hwif->hold;
  335. hwif->dev = tmp_hwif->dev;
  336. #ifdef CONFIG_BLK_DEV_IDEPCI
  337. hwif->cds = tmp_hwif->cds;
  338. #endif
  339. hwif->set_pio_mode = tmp_hwif->set_pio_mode;
  340. hwif->set_dma_mode = tmp_hwif->set_dma_mode;
  341. hwif->mdma_filter = tmp_hwif->mdma_filter;
  342. hwif->udma_filter = tmp_hwif->udma_filter;
  343. hwif->selectproc = tmp_hwif->selectproc;
  344. hwif->reset_poll = tmp_hwif->reset_poll;
  345. hwif->pre_reset = tmp_hwif->pre_reset;
  346. hwif->resetproc = tmp_hwif->resetproc;
  347. hwif->maskproc = tmp_hwif->maskproc;
  348. hwif->quirkproc = tmp_hwif->quirkproc;
  349. hwif->busproc = tmp_hwif->busproc;
  350. hwif->ata_input_data = tmp_hwif->ata_input_data;
  351. hwif->ata_output_data = tmp_hwif->ata_output_data;
  352. hwif->atapi_input_bytes = tmp_hwif->atapi_input_bytes;
  353. hwif->atapi_output_bytes = tmp_hwif->atapi_output_bytes;
  354. hwif->dma_host_set = tmp_hwif->dma_host_set;
  355. hwif->dma_setup = tmp_hwif->dma_setup;
  356. hwif->dma_exec_cmd = tmp_hwif->dma_exec_cmd;
  357. hwif->dma_start = tmp_hwif->dma_start;
  358. hwif->ide_dma_end = tmp_hwif->ide_dma_end;
  359. hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq;
  360. hwif->ide_dma_clear_irq = tmp_hwif->ide_dma_clear_irq;
  361. hwif->dma_lost_irq = tmp_hwif->dma_lost_irq;
  362. hwif->dma_timeout = tmp_hwif->dma_timeout;
  363. hwif->OUTB = tmp_hwif->OUTB;
  364. hwif->OUTBSYNC = tmp_hwif->OUTBSYNC;
  365. hwif->OUTW = tmp_hwif->OUTW;
  366. hwif->OUTSW = tmp_hwif->OUTSW;
  367. hwif->OUTSL = tmp_hwif->OUTSL;
  368. hwif->INB = tmp_hwif->INB;
  369. hwif->INW = tmp_hwif->INW;
  370. hwif->INSW = tmp_hwif->INSW;
  371. hwif->INSL = tmp_hwif->INSL;
  372. hwif->sg_max_nents = tmp_hwif->sg_max_nents;
  373. hwif->mmio = tmp_hwif->mmio;
  374. hwif->rqsize = tmp_hwif->rqsize;
  375. #ifndef CONFIG_BLK_DEV_IDECS
  376. hwif->irq = tmp_hwif->irq;
  377. #endif
  378. hwif->dma_base = tmp_hwif->dma_base;
  379. hwif->dma_command = tmp_hwif->dma_command;
  380. hwif->dma_vendor1 = tmp_hwif->dma_vendor1;
  381. hwif->dma_status = tmp_hwif->dma_status;
  382. hwif->dma_vendor3 = tmp_hwif->dma_vendor3;
  383. hwif->dma_prdtable = tmp_hwif->dma_prdtable;
  384. hwif->config_data = tmp_hwif->config_data;
  385. hwif->select_data = tmp_hwif->select_data;
  386. hwif->extra_base = tmp_hwif->extra_base;
  387. hwif->extra_ports = tmp_hwif->extra_ports;
  388. hwif->hwif_data = tmp_hwif->hwif_data;
  389. }
  390. void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
  391. {
  392. ide_hwgroup_t *hwgroup = hwif->hwgroup;
  393. spin_lock_irq(&ide_lock);
  394. /*
  395. * Remove us from the hwgroup, and free
  396. * the hwgroup if we were the only member
  397. */
  398. if (hwif->next == hwif) {
  399. BUG_ON(hwgroup->hwif != hwif);
  400. kfree(hwgroup);
  401. } else {
  402. /* There is another interface in hwgroup.
  403. * Unlink us, and set hwgroup->drive and ->hwif to
  404. * something sane.
  405. */
  406. ide_hwif_t *g = hwgroup->hwif;
  407. while (g->next != hwif)
  408. g = g->next;
  409. g->next = hwif->next;
  410. if (hwgroup->hwif == hwif) {
  411. /* Chose a random hwif for hwgroup->hwif.
  412. * It's guaranteed that there are no drives
  413. * left in the hwgroup.
  414. */
  415. BUG_ON(hwgroup->drive != NULL);
  416. hwgroup->hwif = g;
  417. }
  418. BUG_ON(hwgroup->hwif == hwif);
  419. }
  420. spin_unlock_irq(&ide_lock);
  421. }
  422. /**
  423. * ide_unregister - free an IDE interface
  424. * @index: index of interface (will change soon to a pointer)
  425. * @init_default: init default hwif flag
  426. * @restore: restore hwif flag
  427. *
  428. * Perform the final unregister of an IDE interface. At the moment
  429. * we don't refcount interfaces so this will also get split up.
  430. *
  431. * Locking:
  432. * The caller must not hold the IDE locks
  433. * The drive present/vanishing is not yet properly locked
  434. * Take care with the callbacks. These have been split to avoid
  435. * deadlocking the IDE layer. The shutdown callback is called
  436. * before we take the lock and free resources. It is up to the
  437. * caller to be sure there is no pending I/O here, and that
  438. * the interface will not be reopened (present/vanishing locking
  439. * isn't yet done BTW). After we commit to the final kill we
  440. * call the cleanup callback with the ide locks held.
  441. *
  442. * Unregister restores the hwif structures to the default state.
  443. * This is raving bonkers.
  444. */
  445. void ide_unregister(unsigned int index, int init_default, int restore)
  446. {
  447. ide_drive_t *drive;
  448. ide_hwif_t *hwif, *g;
  449. static ide_hwif_t tmp_hwif; /* protected by ide_cfg_mtx */
  450. ide_hwgroup_t *hwgroup;
  451. int irq_count = 0, unit;
  452. BUG_ON(index >= MAX_HWIFS);
  453. BUG_ON(in_interrupt());
  454. BUG_ON(irqs_disabled());
  455. mutex_lock(&ide_cfg_mtx);
  456. spin_lock_irq(&ide_lock);
  457. hwif = &ide_hwifs[index];
  458. if (!hwif->present)
  459. goto abort;
  460. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  461. drive = &hwif->drives[unit];
  462. if (!drive->present)
  463. continue;
  464. spin_unlock_irq(&ide_lock);
  465. device_unregister(&drive->gendev);
  466. wait_for_completion(&drive->gendev_rel_comp);
  467. spin_lock_irq(&ide_lock);
  468. }
  469. hwif->present = 0;
  470. spin_unlock_irq(&ide_lock);
  471. ide_proc_unregister_port(hwif);
  472. hwgroup = hwif->hwgroup;
  473. /*
  474. * free the irq if we were the only hwif using it
  475. */
  476. g = hwgroup->hwif;
  477. do {
  478. if (g->irq == hwif->irq)
  479. ++irq_count;
  480. g = g->next;
  481. } while (g != hwgroup->hwif);
  482. if (irq_count == 1)
  483. free_irq(hwif->irq, hwgroup);
  484. ide_remove_port_from_hwgroup(hwif);
  485. device_unregister(&hwif->gendev);
  486. wait_for_completion(&hwif->gendev_rel_comp);
  487. /*
  488. * Remove us from the kernel's knowledge
  489. */
  490. blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
  491. kfree(hwif->sg_table);
  492. unregister_blkdev(hwif->major, hwif->name);
  493. spin_lock_irq(&ide_lock);
  494. if (hwif->dma_base) {
  495. (void) ide_release_dma(hwif);
  496. hwif->dma_base = 0;
  497. hwif->dma_command = 0;
  498. hwif->dma_vendor1 = 0;
  499. hwif->dma_status = 0;
  500. hwif->dma_vendor3 = 0;
  501. hwif->dma_prdtable = 0;
  502. hwif->extra_base = 0;
  503. hwif->extra_ports = 0;
  504. }
  505. /*
  506. * Note that we only release the standard ports,
  507. * and do not even try to handle any extra ports
  508. * allocated for weird IDE interface chipsets.
  509. */
  510. ide_hwif_release_regions(hwif);
  511. /* copy original settings */
  512. tmp_hwif = *hwif;
  513. /* restore hwif data to pristine status */
  514. ide_init_port_data(hwif, index);
  515. if (init_default)
  516. init_hwif_default(hwif, index);
  517. if (restore)
  518. ide_hwif_restore(hwif, &tmp_hwif);
  519. abort:
  520. spin_unlock_irq(&ide_lock);
  521. mutex_unlock(&ide_cfg_mtx);
  522. }
  523. EXPORT_SYMBOL(ide_unregister);
  524. void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
  525. {
  526. memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
  527. hwif->irq = hw->irq;
  528. hwif->noprobe = 0;
  529. hwif->chipset = hw->chipset;
  530. hwif->gendev.parent = hw->dev;
  531. hwif->ack_intr = hw->ack_intr;
  532. }
  533. EXPORT_SYMBOL_GPL(ide_init_port_hw);
  534. ide_hwif_t *ide_deprecated_find_port(unsigned long base)
  535. {
  536. ide_hwif_t *hwif;
  537. int i;
  538. for (i = 0; i < MAX_HWIFS; i++) {
  539. hwif = &ide_hwifs[i];
  540. if (hwif->io_ports[IDE_DATA_OFFSET] == base)
  541. goto found;
  542. }
  543. for (i = 0; i < MAX_HWIFS; i++) {
  544. hwif = &ide_hwifs[i];
  545. if (hwif->hold)
  546. continue;
  547. if (!hwif->present && hwif->mate == NULL)
  548. goto found;
  549. }
  550. hwif = NULL;
  551. found:
  552. return hwif;
  553. }
  554. EXPORT_SYMBOL_GPL(ide_deprecated_find_port);
  555. /**
  556. * ide_register_hw - register IDE interface
  557. * @hw: hardware registers
  558. * @quirkproc: quirkproc function
  559. * @hwifp: pointer to returned hwif
  560. *
  561. * Register an IDE interface, specifying exactly the registers etc.
  562. *
  563. * Returns -1 on error.
  564. */
  565. int ide_register_hw(hw_regs_t *hw, void (*quirkproc)(ide_drive_t *),
  566. ide_hwif_t **hwifp)
  567. {
  568. int index, retry = 1;
  569. ide_hwif_t *hwif;
  570. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  571. do {
  572. hwif = ide_deprecated_find_port(hw->io_ports[IDE_DATA_OFFSET]);
  573. index = hwif->index;
  574. if (hwif)
  575. goto found;
  576. for (index = 0; index < MAX_HWIFS; index++)
  577. ide_unregister(index, 1, 1);
  578. } while (retry--);
  579. return -1;
  580. found:
  581. if (hwif->present)
  582. ide_unregister(index, 0, 1);
  583. else if (!hwif->hold)
  584. ide_init_port_data(hwif, index);
  585. ide_init_port_hw(hwif, hw);
  586. hwif->quirkproc = quirkproc;
  587. idx[0] = index;
  588. ide_device_add(idx, NULL);
  589. if (hwifp)
  590. *hwifp = hwif;
  591. return hwif->present ? index : -1;
  592. }
  593. EXPORT_SYMBOL(ide_register_hw);
  594. /*
  595. * Locks for IDE setting functionality
  596. */
  597. DEFINE_MUTEX(ide_setting_mtx);
  598. EXPORT_SYMBOL_GPL(ide_setting_mtx);
  599. /**
  600. * ide_spin_wait_hwgroup - wait for group
  601. * @drive: drive in the group
  602. *
  603. * Wait for an IDE device group to go non busy and then return
  604. * holding the ide_lock which guards the hwgroup->busy status
  605. * and right to use it.
  606. */
  607. int ide_spin_wait_hwgroup (ide_drive_t *drive)
  608. {
  609. ide_hwgroup_t *hwgroup = HWGROUP(drive);
  610. unsigned long timeout = jiffies + (3 * HZ);
  611. spin_lock_irq(&ide_lock);
  612. while (hwgroup->busy) {
  613. unsigned long lflags;
  614. spin_unlock_irq(&ide_lock);
  615. local_irq_set(lflags);
  616. if (time_after(jiffies, timeout)) {
  617. local_irq_restore(lflags);
  618. printk(KERN_ERR "%s: channel busy\n", drive->name);
  619. return -EBUSY;
  620. }
  621. local_irq_restore(lflags);
  622. spin_lock_irq(&ide_lock);
  623. }
  624. return 0;
  625. }
  626. EXPORT_SYMBOL(ide_spin_wait_hwgroup);
  627. int set_io_32bit(ide_drive_t *drive, int arg)
  628. {
  629. if (drive->no_io_32bit)
  630. return -EPERM;
  631. if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
  632. return -EINVAL;
  633. if (ide_spin_wait_hwgroup(drive))
  634. return -EBUSY;
  635. drive->io_32bit = arg;
  636. spin_unlock_irq(&ide_lock);
  637. return 0;
  638. }
  639. static int set_ksettings(ide_drive_t *drive, int arg)
  640. {
  641. if (arg < 0 || arg > 1)
  642. return -EINVAL;
  643. if (ide_spin_wait_hwgroup(drive))
  644. return -EBUSY;
  645. drive->keep_settings = arg;
  646. spin_unlock_irq(&ide_lock);
  647. return 0;
  648. }
  649. int set_using_dma(ide_drive_t *drive, int arg)
  650. {
  651. #ifdef CONFIG_BLK_DEV_IDEDMA
  652. ide_hwif_t *hwif = drive->hwif;
  653. int err = -EPERM;
  654. if (arg < 0 || arg > 1)
  655. return -EINVAL;
  656. if (!drive->id || !(drive->id->capability & 1))
  657. goto out;
  658. if (hwif->dma_host_set == NULL)
  659. goto out;
  660. err = -EBUSY;
  661. if (ide_spin_wait_hwgroup(drive))
  662. goto out;
  663. /*
  664. * set ->busy flag, unlock and let it ride
  665. */
  666. hwif->hwgroup->busy = 1;
  667. spin_unlock_irq(&ide_lock);
  668. err = 0;
  669. if (arg) {
  670. if (ide_set_dma(drive))
  671. err = -EIO;
  672. } else
  673. ide_dma_off(drive);
  674. /*
  675. * lock, clear ->busy flag and unlock before leaving
  676. */
  677. spin_lock_irq(&ide_lock);
  678. hwif->hwgroup->busy = 0;
  679. spin_unlock_irq(&ide_lock);
  680. out:
  681. return err;
  682. #else
  683. if (arg < 0 || arg > 1)
  684. return -EINVAL;
  685. return -EPERM;
  686. #endif
  687. }
  688. int set_pio_mode(ide_drive_t *drive, int arg)
  689. {
  690. struct request rq;
  691. if (arg < 0 || arg > 255)
  692. return -EINVAL;
  693. if (drive->hwif->set_pio_mode == NULL)
  694. return -ENOSYS;
  695. if (drive->special.b.set_tune)
  696. return -EBUSY;
  697. ide_init_drive_cmd(&rq);
  698. rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
  699. drive->tune_req = (u8) arg;
  700. drive->special.b.set_tune = 1;
  701. (void) ide_do_drive_cmd(drive, &rq, ide_wait);
  702. return 0;
  703. }
  704. static int set_unmaskirq(ide_drive_t *drive, int arg)
  705. {
  706. if (drive->no_unmask)
  707. return -EPERM;
  708. if (arg < 0 || arg > 1)
  709. return -EINVAL;
  710. if (ide_spin_wait_hwgroup(drive))
  711. return -EBUSY;
  712. drive->unmask = arg;
  713. spin_unlock_irq(&ide_lock);
  714. return 0;
  715. }
  716. /**
  717. * system_bus_clock - clock guess
  718. *
  719. * External version of the bus clock guess used by very old IDE drivers
  720. * for things like VLB timings. Should not be used.
  721. */
  722. int system_bus_clock (void)
  723. {
  724. return system_bus_speed;
  725. }
  726. EXPORT_SYMBOL(system_bus_clock);
  727. static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
  728. {
  729. ide_drive_t *drive = dev->driver_data;
  730. ide_hwif_t *hwif = HWIF(drive);
  731. struct request rq;
  732. struct request_pm_state rqpm;
  733. ide_task_t args;
  734. int ret;
  735. /* Call ACPI _GTM only once */
  736. if (!(drive->dn % 2))
  737. ide_acpi_get_timing(hwif);
  738. memset(&rq, 0, sizeof(rq));
  739. memset(&rqpm, 0, sizeof(rqpm));
  740. memset(&args, 0, sizeof(args));
  741. rq.cmd_type = REQ_TYPE_PM_SUSPEND;
  742. rq.special = &args;
  743. rq.data = &rqpm;
  744. rqpm.pm_step = ide_pm_state_start_suspend;
  745. if (mesg.event == PM_EVENT_PRETHAW)
  746. mesg.event = PM_EVENT_FREEZE;
  747. rqpm.pm_state = mesg.event;
  748. ret = ide_do_drive_cmd(drive, &rq, ide_wait);
  749. /* only call ACPI _PS3 after both drivers are suspended */
  750. if (!ret && (((drive->dn % 2) && hwif->drives[0].present
  751. && hwif->drives[1].present)
  752. || !hwif->drives[0].present
  753. || !hwif->drives[1].present))
  754. ide_acpi_set_state(hwif, 0);
  755. return ret;
  756. }
  757. static int generic_ide_resume(struct device *dev)
  758. {
  759. ide_drive_t *drive = dev->driver_data;
  760. ide_hwif_t *hwif = HWIF(drive);
  761. struct request rq;
  762. struct request_pm_state rqpm;
  763. ide_task_t args;
  764. int err;
  765. /* Call ACPI _STM only once */
  766. if (!(drive->dn % 2)) {
  767. ide_acpi_set_state(hwif, 1);
  768. ide_acpi_push_timing(hwif);
  769. }
  770. ide_acpi_exec_tfs(drive);
  771. memset(&rq, 0, sizeof(rq));
  772. memset(&rqpm, 0, sizeof(rqpm));
  773. memset(&args, 0, sizeof(args));
  774. rq.cmd_type = REQ_TYPE_PM_RESUME;
  775. rq.special = &args;
  776. rq.data = &rqpm;
  777. rqpm.pm_step = ide_pm_state_start_resume;
  778. rqpm.pm_state = PM_EVENT_ON;
  779. err = ide_do_drive_cmd(drive, &rq, ide_head_wait);
  780. if (err == 0 && dev->driver) {
  781. ide_driver_t *drv = to_ide_driver(dev->driver);
  782. if (drv->resume)
  783. drv->resume(drive);
  784. }
  785. return err;
  786. }
  787. int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
  788. unsigned int cmd, unsigned long arg)
  789. {
  790. unsigned long flags;
  791. ide_driver_t *drv;
  792. void __user *p = (void __user *)arg;
  793. int err = 0, (*setfunc)(ide_drive_t *, int);
  794. u8 *val;
  795. switch (cmd) {
  796. case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val;
  797. case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
  798. case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val;
  799. case HDIO_GET_DMA: val = &drive->using_dma; goto read_val;
  800. case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val;
  801. case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val;
  802. case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val;
  803. case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val;
  804. case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val;
  805. }
  806. switch (cmd) {
  807. case HDIO_OBSOLETE_IDENTITY:
  808. case HDIO_GET_IDENTITY:
  809. if (bdev != bdev->bd_contains)
  810. return -EINVAL;
  811. if (drive->id_read == 0)
  812. return -ENOMSG;
  813. if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
  814. return -EFAULT;
  815. return 0;
  816. case HDIO_GET_NICE:
  817. return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
  818. drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
  819. drive->nice1 << IDE_NICE_1,
  820. (long __user *) arg);
  821. #ifdef CONFIG_IDE_TASK_IOCTL
  822. case HDIO_DRIVE_TASKFILE:
  823. if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
  824. return -EACCES;
  825. switch(drive->media) {
  826. case ide_disk:
  827. return ide_taskfile_ioctl(drive, cmd, arg);
  828. default:
  829. return -ENOMSG;
  830. }
  831. #endif /* CONFIG_IDE_TASK_IOCTL */
  832. case HDIO_DRIVE_CMD:
  833. if (!capable(CAP_SYS_RAWIO))
  834. return -EACCES;
  835. return ide_cmd_ioctl(drive, cmd, arg);
  836. case HDIO_DRIVE_TASK:
  837. if (!capable(CAP_SYS_RAWIO))
  838. return -EACCES;
  839. return ide_task_ioctl(drive, cmd, arg);
  840. case HDIO_SCAN_HWIF:
  841. {
  842. hw_regs_t hw;
  843. int args[3];
  844. if (!capable(CAP_SYS_RAWIO)) return -EACCES;
  845. if (copy_from_user(args, p, 3 * sizeof(int)))
  846. return -EFAULT;
  847. memset(&hw, 0, sizeof(hw));
  848. ide_init_hwif_ports(&hw, (unsigned long) args[0],
  849. (unsigned long) args[1], NULL);
  850. hw.irq = args[2];
  851. if (ide_register_hw(&hw, NULL, NULL) == -1)
  852. return -EIO;
  853. return 0;
  854. }
  855. case HDIO_UNREGISTER_HWIF:
  856. if (!capable(CAP_SYS_RAWIO)) return -EACCES;
  857. /* (arg > MAX_HWIFS) checked in function */
  858. ide_unregister(arg, 1, 1);
  859. return 0;
  860. case HDIO_SET_NICE:
  861. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  862. if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
  863. return -EPERM;
  864. drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
  865. drv = *(ide_driver_t **)bdev->bd_disk->private_data;
  866. if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
  867. drive->dsc_overlap = 0;
  868. return -EPERM;
  869. }
  870. drive->nice1 = (arg >> IDE_NICE_1) & 1;
  871. return 0;
  872. case HDIO_DRIVE_RESET:
  873. {
  874. unsigned long flags;
  875. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  876. /*
  877. * Abort the current command on the
  878. * group if there is one, taking
  879. * care not to allow anything else
  880. * to be queued and to die on the
  881. * spot if we miss one somehow
  882. */
  883. spin_lock_irqsave(&ide_lock, flags);
  884. if (HWGROUP(drive)->resetting) {
  885. spin_unlock_irqrestore(&ide_lock, flags);
  886. return -EBUSY;
  887. }
  888. ide_abort(drive, "drive reset");
  889. BUG_ON(HWGROUP(drive)->handler);
  890. /* Ensure nothing gets queued after we
  891. drop the lock. Reset will clear the busy */
  892. HWGROUP(drive)->busy = 1;
  893. spin_unlock_irqrestore(&ide_lock, flags);
  894. (void) ide_do_reset(drive);
  895. return 0;
  896. }
  897. case HDIO_GET_BUSSTATE:
  898. if (!capable(CAP_SYS_ADMIN))
  899. return -EACCES;
  900. if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
  901. return -EFAULT;
  902. return 0;
  903. case HDIO_SET_BUSSTATE:
  904. if (!capable(CAP_SYS_ADMIN))
  905. return -EACCES;
  906. if (HWIF(drive)->busproc)
  907. return HWIF(drive)->busproc(drive, (int)arg);
  908. return -EOPNOTSUPP;
  909. default:
  910. return -EINVAL;
  911. }
  912. read_val:
  913. mutex_lock(&ide_setting_mtx);
  914. spin_lock_irqsave(&ide_lock, flags);
  915. err = *val;
  916. spin_unlock_irqrestore(&ide_lock, flags);
  917. mutex_unlock(&ide_setting_mtx);
  918. return err >= 0 ? put_user(err, (long __user *)arg) : err;
  919. set_val:
  920. if (bdev != bdev->bd_contains)
  921. err = -EINVAL;
  922. else {
  923. if (!capable(CAP_SYS_ADMIN))
  924. err = -EACCES;
  925. else {
  926. mutex_lock(&ide_setting_mtx);
  927. err = setfunc(drive, arg);
  928. mutex_unlock(&ide_setting_mtx);
  929. }
  930. }
  931. return err;
  932. }
  933. EXPORT_SYMBOL(generic_ide_ioctl);
  934. /*
  935. * stridx() returns the offset of c within s,
  936. * or -1 if c is '\0' or not found within s.
  937. */
  938. static int __init stridx (const char *s, char c)
  939. {
  940. char *i = strchr(s, c);
  941. return (i && c) ? i - s : -1;
  942. }
  943. /*
  944. * match_parm() does parsing for ide_setup():
  945. *
  946. * 1. the first char of s must be '='.
  947. * 2. if the remainder matches one of the supplied keywords,
  948. * the index (1 based) of the keyword is negated and returned.
  949. * 3. if the remainder is a series of no more than max_vals numbers
  950. * separated by commas, the numbers are saved in vals[] and a
  951. * count of how many were saved is returned. Base10 is assumed,
  952. * and base16 is allowed when prefixed with "0x".
  953. * 4. otherwise, zero is returned.
  954. */
  955. static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
  956. {
  957. static const char *decimal = "0123456789";
  958. static const char *hex = "0123456789abcdef";
  959. int i, n;
  960. if (*s++ == '=') {
  961. /*
  962. * Try matching against the supplied keywords,
  963. * and return -(index+1) if we match one
  964. */
  965. if (keywords != NULL) {
  966. for (i = 0; *keywords != NULL; ++i) {
  967. if (!strcmp(s, *keywords++))
  968. return -(i+1);
  969. }
  970. }
  971. /*
  972. * Look for a series of no more than "max_vals"
  973. * numeric values separated by commas, in base10,
  974. * or base16 when prefixed with "0x".
  975. * Return a count of how many were found.
  976. */
  977. for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
  978. vals[n] = i;
  979. while ((i = stridx(decimal, *++s)) >= 0)
  980. vals[n] = (vals[n] * 10) + i;
  981. if (*s == 'x' && !vals[n]) {
  982. while ((i = stridx(hex, *++s)) >= 0)
  983. vals[n] = (vals[n] * 0x10) + i;
  984. }
  985. if (++n == max_vals)
  986. break;
  987. if (*s == ',' || *s == ';')
  988. ++s;
  989. }
  990. if (!*s)
  991. return n;
  992. }
  993. return 0; /* zero = nothing matched */
  994. }
  995. extern int probe_ali14xx;
  996. extern int probe_umc8672;
  997. extern int probe_dtc2278;
  998. extern int probe_ht6560b;
  999. extern int probe_qd65xx;
  1000. extern int cmd640_vlb;
  1001. static int __initdata is_chipset_set[MAX_HWIFS];
  1002. /*
  1003. * ide_setup() gets called VERY EARLY during initialization,
  1004. * to handle kernel "command line" strings beginning with "hdx=" or "ide".
  1005. *
  1006. * Remember to update Documentation/ide.txt if you change something here.
  1007. */
  1008. static int __init ide_setup(char *s)
  1009. {
  1010. int i, vals[3];
  1011. ide_hwif_t *hwif;
  1012. ide_drive_t *drive;
  1013. unsigned int hw, unit;
  1014. const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
  1015. const char max_hwif = '0' + (MAX_HWIFS - 1);
  1016. if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
  1017. return 0; /* driver and not us */
  1018. if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
  1019. return 0;
  1020. printk(KERN_INFO "ide_setup: %s", s);
  1021. init_ide_data ();
  1022. #ifdef CONFIG_BLK_DEV_IDEDOUBLER
  1023. if (!strcmp(s, "ide=doubler")) {
  1024. extern int ide_doubler;
  1025. printk(" : Enabled support for IDE doublers\n");
  1026. ide_doubler = 1;
  1027. return 1;
  1028. }
  1029. #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
  1030. if (!strcmp(s, "ide=nodma")) {
  1031. printk(" : Prevented DMA\n");
  1032. noautodma = 1;
  1033. goto obsolete_option;
  1034. }
  1035. #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
  1036. if (!strcmp(s, "ide=reverse")) {
  1037. ide_scan_direction = 1;
  1038. printk(" : Enabled support for IDE inverse scan order.\n");
  1039. goto obsolete_option;
  1040. }
  1041. #endif
  1042. #ifdef CONFIG_BLK_DEV_IDEACPI
  1043. if (!strcmp(s, "ide=noacpi")) {
  1044. //printk(" : Disable IDE ACPI support.\n");
  1045. ide_noacpi = 1;
  1046. return 1;
  1047. }
  1048. if (!strcmp(s, "ide=acpigtf")) {
  1049. //printk(" : Enable IDE ACPI _GTF support.\n");
  1050. ide_noacpitfs = 0;
  1051. return 1;
  1052. }
  1053. if (!strcmp(s, "ide=acpionboot")) {
  1054. //printk(" : Call IDE ACPI methods on boot.\n");
  1055. ide_noacpionboot = 0;
  1056. return 1;
  1057. }
  1058. #endif /* CONFIG_BLK_DEV_IDEACPI */
  1059. /*
  1060. * Look for drive options: "hdx="
  1061. */
  1062. if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
  1063. const char *hd_words[] = {
  1064. "none", "noprobe", "nowerr", "cdrom", "nodma",
  1065. "autotune", "noautotune", "-8", "-9", "-10",
  1066. "noflush", "remap", "remap63", "scsi", NULL };
  1067. unit = s[2] - 'a';
  1068. hw = unit / MAX_DRIVES;
  1069. unit = unit % MAX_DRIVES;
  1070. hwif = &ide_hwifs[hw];
  1071. drive = &hwif->drives[unit];
  1072. if (strncmp(s + 4, "ide-", 4) == 0) {
  1073. strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
  1074. goto done;
  1075. }
  1076. switch (match_parm(&s[3], hd_words, vals, 3)) {
  1077. case -1: /* "none" */
  1078. case -2: /* "noprobe" */
  1079. drive->noprobe = 1;
  1080. goto done;
  1081. case -3: /* "nowerr" */
  1082. drive->bad_wstat = BAD_R_STAT;
  1083. hwif->noprobe = 0;
  1084. goto done;
  1085. case -4: /* "cdrom" */
  1086. drive->present = 1;
  1087. drive->media = ide_cdrom;
  1088. /* an ATAPI device ignores DRDY */
  1089. drive->ready_stat = 0;
  1090. hwif->noprobe = 0;
  1091. goto done;
  1092. case -5: /* nodma */
  1093. drive->nodma = 1;
  1094. goto done;
  1095. case -6: /* "autotune" */
  1096. drive->autotune = IDE_TUNE_AUTO;
  1097. goto obsolete_option;
  1098. case -7: /* "noautotune" */
  1099. drive->autotune = IDE_TUNE_NOAUTO;
  1100. goto obsolete_option;
  1101. case -11: /* noflush */
  1102. drive->noflush = 1;
  1103. goto done;
  1104. case -12: /* "remap" */
  1105. drive->remap_0_to_1 = 1;
  1106. goto done;
  1107. case -13: /* "remap63" */
  1108. drive->sect0 = 63;
  1109. goto done;
  1110. case -14: /* "scsi" */
  1111. drive->scsi = 1;
  1112. goto done;
  1113. case 3: /* cyl,head,sect */
  1114. drive->media = ide_disk;
  1115. drive->ready_stat = READY_STAT;
  1116. drive->cyl = drive->bios_cyl = vals[0];
  1117. drive->head = drive->bios_head = vals[1];
  1118. drive->sect = drive->bios_sect = vals[2];
  1119. drive->present = 1;
  1120. drive->forced_geom = 1;
  1121. hwif->noprobe = 0;
  1122. goto done;
  1123. default:
  1124. goto bad_option;
  1125. }
  1126. }
  1127. if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
  1128. goto bad_option;
  1129. /*
  1130. * Look for bus speed option: "idebus="
  1131. */
  1132. if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
  1133. if (match_parm(&s[6], NULL, vals, 1) != 1)
  1134. goto bad_option;
  1135. if (vals[0] >= 20 && vals[0] <= 66) {
  1136. idebus_parameter = vals[0];
  1137. } else
  1138. printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
  1139. goto done;
  1140. }
  1141. /*
  1142. * Look for interface options: "idex="
  1143. */
  1144. if (s[3] >= '0' && s[3] <= max_hwif) {
  1145. /*
  1146. * Be VERY CAREFUL changing this: note hardcoded indexes below
  1147. * (-8, -9, -10) are reserved to ease the hardcoding.
  1148. */
  1149. static const char *ide_words[] = {
  1150. "noprobe", "serialize", "minus3", "minus4",
  1151. "reset", "minus6", "ata66", "minus8", "minus9",
  1152. "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
  1153. "dtc2278", "umc8672", "ali14xx", NULL };
  1154. hw_regs_t hwregs;
  1155. hw = s[3] - '0';
  1156. hwif = &ide_hwifs[hw];
  1157. i = match_parm(&s[4], ide_words, vals, 3);
  1158. /*
  1159. * Cryptic check to ensure chipset not already set for hwif.
  1160. * Note: we can't depend on hwif->chipset here.
  1161. */
  1162. if ((i >= -18 && i <= -11) || (i > 0 && i <= 3)) {
  1163. /* chipset already specified */
  1164. if (is_chipset_set[hw])
  1165. goto bad_option;
  1166. if (i > -18 && i <= -11) {
  1167. /* these drivers are for "ide0=" only */
  1168. if (hw != 0)
  1169. goto bad_hwif;
  1170. /* chipset already specified for 2nd port */
  1171. if (is_chipset_set[hw+1])
  1172. goto bad_option;
  1173. }
  1174. is_chipset_set[hw] = 1;
  1175. printk("\n");
  1176. }
  1177. switch (i) {
  1178. #ifdef CONFIG_BLK_DEV_ALI14XX
  1179. case -17: /* "ali14xx" */
  1180. probe_ali14xx = 1;
  1181. goto done;
  1182. #endif
  1183. #ifdef CONFIG_BLK_DEV_UMC8672
  1184. case -16: /* "umc8672" */
  1185. probe_umc8672 = 1;
  1186. goto done;
  1187. #endif
  1188. #ifdef CONFIG_BLK_DEV_DTC2278
  1189. case -15: /* "dtc2278" */
  1190. probe_dtc2278 = 1;
  1191. goto done;
  1192. #endif
  1193. #ifdef CONFIG_BLK_DEV_CMD640
  1194. case -14: /* "cmd640_vlb" */
  1195. cmd640_vlb = 1;
  1196. goto done;
  1197. #endif
  1198. #ifdef CONFIG_BLK_DEV_HT6560B
  1199. case -13: /* "ht6560b" */
  1200. probe_ht6560b = 1;
  1201. goto done;
  1202. #endif
  1203. #ifdef CONFIG_BLK_DEV_QD65XX
  1204. case -12: /* "qd65xx" */
  1205. probe_qd65xx = 1;
  1206. goto done;
  1207. #endif
  1208. #ifdef CONFIG_BLK_DEV_4DRIVES
  1209. case -11: /* "four" drives on one set of ports */
  1210. {
  1211. ide_hwif_t *mate = &ide_hwifs[hw^1];
  1212. mate->drives[0].select.all ^= 0x20;
  1213. mate->drives[1].select.all ^= 0x20;
  1214. hwif->chipset = mate->chipset = ide_4drives;
  1215. mate->irq = hwif->irq;
  1216. memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
  1217. hwif->mate = mate;
  1218. mate->mate = hwif;
  1219. hwif->serialized = mate->serialized = 1;
  1220. goto obsolete_option;
  1221. }
  1222. #endif /* CONFIG_BLK_DEV_4DRIVES */
  1223. case -10: /* minus10 */
  1224. case -9: /* minus9 */
  1225. case -8: /* minus8 */
  1226. case -6:
  1227. case -4:
  1228. case -3:
  1229. goto bad_option;
  1230. case -7: /* ata66 */
  1231. #ifdef CONFIG_BLK_DEV_IDEPCI
  1232. /*
  1233. * Use ATA_CBL_PATA40_SHORT so drive side
  1234. * cable detection is also overriden.
  1235. */
  1236. hwif->cbl = ATA_CBL_PATA40_SHORT;
  1237. goto obsolete_option;
  1238. #else
  1239. goto bad_hwif;
  1240. #endif
  1241. case -5: /* "reset" */
  1242. hwif->reset = 1;
  1243. goto obsolete_option;
  1244. case -2: /* "serialize" */
  1245. hwif->mate = &ide_hwifs[hw^1];
  1246. hwif->mate->mate = hwif;
  1247. hwif->serialized = hwif->mate->serialized = 1;
  1248. goto obsolete_option;
  1249. case -1: /* "noprobe" */
  1250. hwif->noprobe = 1;
  1251. goto done;
  1252. case 1: /* base */
  1253. vals[1] = vals[0] + 0x206; /* default ctl */
  1254. case 2: /* base,ctl */
  1255. vals[2] = 0; /* default irq = probe for it */
  1256. case 3: /* base,ctl,irq */
  1257. memset(&hwregs, 0, sizeof(hwregs));
  1258. ide_init_hwif_ports(&hwregs, vals[0], vals[1], &hwif->irq);
  1259. memcpy(hwif->io_ports, hwregs.io_ports, sizeof(hwif->io_ports));
  1260. hwif->irq = vals[2];
  1261. hwif->noprobe = 0;
  1262. hwif->chipset = ide_forced;
  1263. goto obsolete_option;
  1264. case 0: goto bad_option;
  1265. default:
  1266. printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
  1267. return 1;
  1268. }
  1269. }
  1270. bad_option:
  1271. printk(" -- BAD OPTION\n");
  1272. return 1;
  1273. obsolete_option:
  1274. printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
  1275. return 1;
  1276. bad_hwif:
  1277. printk("-- NOT SUPPORTED ON ide%d", hw);
  1278. done:
  1279. printk("\n");
  1280. return 1;
  1281. }
  1282. EXPORT_SYMBOL(ide_lock);
  1283. static int ide_bus_match(struct device *dev, struct device_driver *drv)
  1284. {
  1285. return 1;
  1286. }
  1287. static char *media_string(ide_drive_t *drive)
  1288. {
  1289. switch (drive->media) {
  1290. case ide_disk:
  1291. return "disk";
  1292. case ide_cdrom:
  1293. return "cdrom";
  1294. case ide_tape:
  1295. return "tape";
  1296. case ide_floppy:
  1297. return "floppy";
  1298. case ide_optical:
  1299. return "optical";
  1300. default:
  1301. return "UNKNOWN";
  1302. }
  1303. }
  1304. static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
  1305. {
  1306. ide_drive_t *drive = to_ide_device(dev);
  1307. return sprintf(buf, "%s\n", media_string(drive));
  1308. }
  1309. static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
  1310. {
  1311. ide_drive_t *drive = to_ide_device(dev);
  1312. return sprintf(buf, "%s\n", drive->name);
  1313. }
  1314. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
  1315. {
  1316. ide_drive_t *drive = to_ide_device(dev);
  1317. return sprintf(buf, "ide:m-%s\n", media_string(drive));
  1318. }
  1319. static ssize_t model_show(struct device *dev, struct device_attribute *attr,
  1320. char *buf)
  1321. {
  1322. ide_drive_t *drive = to_ide_device(dev);
  1323. return sprintf(buf, "%s\n", drive->id->model);
  1324. }
  1325. static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
  1326. char *buf)
  1327. {
  1328. ide_drive_t *drive = to_ide_device(dev);
  1329. return sprintf(buf, "%s\n", drive->id->fw_rev);
  1330. }
  1331. static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
  1332. char *buf)
  1333. {
  1334. ide_drive_t *drive = to_ide_device(dev);
  1335. return sprintf(buf, "%s\n", drive->id->serial_no);
  1336. }
  1337. static struct device_attribute ide_dev_attrs[] = {
  1338. __ATTR_RO(media),
  1339. __ATTR_RO(drivename),
  1340. __ATTR_RO(modalias),
  1341. __ATTR_RO(model),
  1342. __ATTR_RO(firmware),
  1343. __ATTR(serial, 0400, serial_show, NULL),
  1344. __ATTR_NULL
  1345. };
  1346. static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
  1347. {
  1348. ide_drive_t *drive = to_ide_device(dev);
  1349. add_uevent_var(env, "MEDIA=%s", media_string(drive));
  1350. add_uevent_var(env, "DRIVENAME=%s", drive->name);
  1351. add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive));
  1352. return 0;
  1353. }
  1354. static int generic_ide_probe(struct device *dev)
  1355. {
  1356. ide_drive_t *drive = to_ide_device(dev);
  1357. ide_driver_t *drv = to_ide_driver(dev->driver);
  1358. return drv->probe ? drv->probe(drive) : -ENODEV;
  1359. }
  1360. static int generic_ide_remove(struct device *dev)
  1361. {
  1362. ide_drive_t *drive = to_ide_device(dev);
  1363. ide_driver_t *drv = to_ide_driver(dev->driver);
  1364. if (drv->remove)
  1365. drv->remove(drive);
  1366. return 0;
  1367. }
  1368. static void generic_ide_shutdown(struct device *dev)
  1369. {
  1370. ide_drive_t *drive = to_ide_device(dev);
  1371. ide_driver_t *drv = to_ide_driver(dev->driver);
  1372. if (dev->driver && drv->shutdown)
  1373. drv->shutdown(drive);
  1374. }
  1375. struct bus_type ide_bus_type = {
  1376. .name = "ide",
  1377. .match = ide_bus_match,
  1378. .uevent = ide_uevent,
  1379. .probe = generic_ide_probe,
  1380. .remove = generic_ide_remove,
  1381. .shutdown = generic_ide_shutdown,
  1382. .dev_attrs = ide_dev_attrs,
  1383. .suspend = generic_ide_suspend,
  1384. .resume = generic_ide_resume,
  1385. };
  1386. EXPORT_SYMBOL_GPL(ide_bus_type);
  1387. /*
  1388. * This is gets invoked once during initialization, to set *everything* up
  1389. */
  1390. static int __init ide_init(void)
  1391. {
  1392. int ret;
  1393. printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
  1394. system_bus_speed = ide_system_bus_speed();
  1395. printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
  1396. "for PIO modes%s\n", system_bus_speed,
  1397. idebus_parameter ? "" : "; override with idebus=xx");
  1398. ret = bus_register(&ide_bus_type);
  1399. if (ret < 0) {
  1400. printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
  1401. return ret;
  1402. }
  1403. init_ide_data();
  1404. proc_ide_create();
  1405. return 0;
  1406. }
  1407. #ifdef MODULE
  1408. static char *options = NULL;
  1409. module_param(options, charp, 0);
  1410. MODULE_LICENSE("GPL");
  1411. static void __init parse_options (char *line)
  1412. {
  1413. char *next = line;
  1414. if (line == NULL || !*line)
  1415. return;
  1416. while ((line = next) != NULL) {
  1417. if ((next = strchr(line,' ')) != NULL)
  1418. *next++ = 0;
  1419. if (!ide_setup(line))
  1420. printk (KERN_INFO "Unknown option '%s'\n", line);
  1421. }
  1422. }
  1423. int __init init_module (void)
  1424. {
  1425. parse_options(options);
  1426. return ide_init();
  1427. }
  1428. void __exit cleanup_module (void)
  1429. {
  1430. int index;
  1431. for (index = 0; index < MAX_HWIFS; ++index)
  1432. ide_unregister(index, 0, 0);
  1433. proc_ide_destroy();
  1434. bus_unregister(&ide_bus_type);
  1435. }
  1436. #else /* !MODULE */
  1437. __setup("", ide_setup);
  1438. module_init(ide_init);
  1439. #endif /* MODULE */