pmac.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  1. /*
  2. * Support for IDE interfaces on PowerMacs.
  3. *
  4. * These IDE interfaces are memory-mapped and have a DBDMA channel
  5. * for doing DMA.
  6. *
  7. * Copyright (C) 1998-2003 Paul Mackerras & Ben. Herrenschmidt
  8. * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. *
  15. * Some code taken from drivers/ide/ide-dma.c:
  16. *
  17. * Copyright (c) 1995-1998 Mark Lord
  18. *
  19. * TODO: - Use pre-calculated (kauai) timing tables all the time and
  20. * get rid of the "rounded" tables used previously, so we have the
  21. * same table format for all controllers and can then just have one
  22. * big table
  23. *
  24. */
  25. #include <linux/types.h>
  26. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <linux/delay.h>
  29. #include <linux/ide.h>
  30. #include <linux/notifier.h>
  31. #include <linux/reboot.h>
  32. #include <linux/pci.h>
  33. #include <linux/adb.h>
  34. #include <linux/pmu.h>
  35. #include <linux/scatterlist.h>
  36. #include <asm/prom.h>
  37. #include <asm/io.h>
  38. #include <asm/dbdma.h>
  39. #include <asm/ide.h>
  40. #include <asm/pci-bridge.h>
  41. #include <asm/machdep.h>
  42. #include <asm/pmac_feature.h>
  43. #include <asm/sections.h>
  44. #include <asm/irq.h>
  45. #ifndef CONFIG_PPC64
  46. #include <asm/mediabay.h>
  47. #endif
  48. #include "../ide-timing.h"
  49. #undef IDE_PMAC_DEBUG
  50. #define DMA_WAIT_TIMEOUT 50
  51. typedef struct pmac_ide_hwif {
  52. unsigned long regbase;
  53. int irq;
  54. int kind;
  55. int aapl_bus_id;
  56. unsigned cable_80 : 1;
  57. unsigned mediabay : 1;
  58. unsigned broken_dma : 1;
  59. unsigned broken_dma_warn : 1;
  60. struct device_node* node;
  61. struct macio_dev *mdev;
  62. u32 timings[4];
  63. volatile u32 __iomem * *kauai_fcr;
  64. #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
  65. /* Those fields are duplicating what is in hwif. We currently
  66. * can't use the hwif ones because of some assumptions that are
  67. * beeing done by the generic code about the kind of dma controller
  68. * and format of the dma table. This will have to be fixed though.
  69. */
  70. volatile struct dbdma_regs __iomem * dma_regs;
  71. struct dbdma_cmd* dma_table_cpu;
  72. #endif
  73. } pmac_ide_hwif_t;
  74. enum {
  75. controller_ohare, /* OHare based */
  76. controller_heathrow, /* Heathrow/Paddington */
  77. controller_kl_ata3, /* KeyLargo ATA-3 */
  78. controller_kl_ata4, /* KeyLargo ATA-4 */
  79. controller_un_ata6, /* UniNorth2 ATA-6 */
  80. controller_k2_ata6, /* K2 ATA-6 */
  81. controller_sh_ata6, /* Shasta ATA-6 */
  82. };
  83. static const char* model_name[] = {
  84. "OHare ATA", /* OHare based */
  85. "Heathrow ATA", /* Heathrow/Paddington */
  86. "KeyLargo ATA-3", /* KeyLargo ATA-3 (MDMA only) */
  87. "KeyLargo ATA-4", /* KeyLargo ATA-4 (UDMA/66) */
  88. "UniNorth ATA-6", /* UniNorth2 ATA-6 (UDMA/100) */
  89. "K2 ATA-6", /* K2 ATA-6 (UDMA/100) */
  90. "Shasta ATA-6", /* Shasta ATA-6 (UDMA/133) */
  91. };
  92. /*
  93. * Extra registers, both 32-bit little-endian
  94. */
  95. #define IDE_TIMING_CONFIG 0x200
  96. #define IDE_INTERRUPT 0x300
  97. /* Kauai (U2) ATA has different register setup */
  98. #define IDE_KAUAI_PIO_CONFIG 0x200
  99. #define IDE_KAUAI_ULTRA_CONFIG 0x210
  100. #define IDE_KAUAI_POLL_CONFIG 0x220
  101. /*
  102. * Timing configuration register definitions
  103. */
  104. /* Number of IDE_SYSCLK_NS ticks, argument is in nanoseconds */
  105. #define SYSCLK_TICKS(t) (((t) + IDE_SYSCLK_NS - 1) / IDE_SYSCLK_NS)
  106. #define SYSCLK_TICKS_66(t) (((t) + IDE_SYSCLK_66_NS - 1) / IDE_SYSCLK_66_NS)
  107. #define IDE_SYSCLK_NS 30 /* 33Mhz cell */
  108. #define IDE_SYSCLK_66_NS 15 /* 66Mhz cell */
  109. /* 133Mhz cell, found in shasta.
  110. * See comments about 100 Mhz Uninorth 2...
  111. * Note that PIO_MASK and MDMA_MASK seem to overlap
  112. */
  113. #define TR_133_PIOREG_PIO_MASK 0xff000fff
  114. #define TR_133_PIOREG_MDMA_MASK 0x00fff800
  115. #define TR_133_UDMAREG_UDMA_MASK 0x0003ffff
  116. #define TR_133_UDMAREG_UDMA_EN 0x00000001
  117. /* 100Mhz cell, found in Uninorth 2. I don't have much infos about
  118. * this one yet, it appears as a pci device (106b/0033) on uninorth
  119. * internal PCI bus and it's clock is controlled like gem or fw. It
  120. * appears to be an evolution of keylargo ATA4 with a timing register
  121. * extended to 2 32bits registers and a similar DBDMA channel. Other
  122. * registers seem to exist but I can't tell much about them.
  123. *
  124. * So far, I'm using pre-calculated tables for this extracted from
  125. * the values used by the MacOS X driver.
  126. *
  127. * The "PIO" register controls PIO and MDMA timings, the "ULTRA"
  128. * register controls the UDMA timings. At least, it seems bit 0
  129. * of this one enables UDMA vs. MDMA, and bits 4..7 are the
  130. * cycle time in units of 10ns. Bits 8..15 are used by I don't
  131. * know their meaning yet
  132. */
  133. #define TR_100_PIOREG_PIO_MASK 0xff000fff
  134. #define TR_100_PIOREG_MDMA_MASK 0x00fff000
  135. #define TR_100_UDMAREG_UDMA_MASK 0x0000ffff
  136. #define TR_100_UDMAREG_UDMA_EN 0x00000001
  137. /* 66Mhz cell, found in KeyLargo. Can do ultra mode 0 to 2 on
  138. * 40 connector cable and to 4 on 80 connector one.
  139. * Clock unit is 15ns (66Mhz)
  140. *
  141. * 3 Values can be programmed:
  142. * - Write data setup, which appears to match the cycle time. They
  143. * also call it DIOW setup.
  144. * - Ready to pause time (from spec)
  145. * - Address setup. That one is weird. I don't see where exactly
  146. * it fits in UDMA cycles, I got it's name from an obscure piece
  147. * of commented out code in Darwin. They leave it to 0, we do as
  148. * well, despite a comment that would lead to think it has a
  149. * min value of 45ns.
  150. * Apple also add 60ns to the write data setup (or cycle time ?) on
  151. * reads.
  152. */
  153. #define TR_66_UDMA_MASK 0xfff00000
  154. #define TR_66_UDMA_EN 0x00100000 /* Enable Ultra mode for DMA */
  155. #define TR_66_UDMA_ADDRSETUP_MASK 0xe0000000 /* Address setup */
  156. #define TR_66_UDMA_ADDRSETUP_SHIFT 29
  157. #define TR_66_UDMA_RDY2PAUS_MASK 0x1e000000 /* Ready 2 pause time */
  158. #define TR_66_UDMA_RDY2PAUS_SHIFT 25
  159. #define TR_66_UDMA_WRDATASETUP_MASK 0x01e00000 /* Write data setup time */
  160. #define TR_66_UDMA_WRDATASETUP_SHIFT 21
  161. #define TR_66_MDMA_MASK 0x000ffc00
  162. #define TR_66_MDMA_RECOVERY_MASK 0x000f8000
  163. #define TR_66_MDMA_RECOVERY_SHIFT 15
  164. #define TR_66_MDMA_ACCESS_MASK 0x00007c00
  165. #define TR_66_MDMA_ACCESS_SHIFT 10
  166. #define TR_66_PIO_MASK 0x000003ff
  167. #define TR_66_PIO_RECOVERY_MASK 0x000003e0
  168. #define TR_66_PIO_RECOVERY_SHIFT 5
  169. #define TR_66_PIO_ACCESS_MASK 0x0000001f
  170. #define TR_66_PIO_ACCESS_SHIFT 0
  171. /* 33Mhz cell, found in OHare, Heathrow (& Paddington) and KeyLargo
  172. * Can do pio & mdma modes, clock unit is 30ns (33Mhz)
  173. *
  174. * The access time and recovery time can be programmed. Some older
  175. * Darwin code base limit OHare to 150ns cycle time. I decided to do
  176. * the same here fore safety against broken old hardware ;)
  177. * The HalfTick bit, when set, adds half a clock (15ns) to the access
  178. * time and removes one from recovery. It's not supported on KeyLargo
  179. * implementation afaik. The E bit appears to be set for PIO mode 0 and
  180. * is used to reach long timings used in this mode.
  181. */
  182. #define TR_33_MDMA_MASK 0x003ff800
  183. #define TR_33_MDMA_RECOVERY_MASK 0x001f0000
  184. #define TR_33_MDMA_RECOVERY_SHIFT 16
  185. #define TR_33_MDMA_ACCESS_MASK 0x0000f800
  186. #define TR_33_MDMA_ACCESS_SHIFT 11
  187. #define TR_33_MDMA_HALFTICK 0x00200000
  188. #define TR_33_PIO_MASK 0x000007ff
  189. #define TR_33_PIO_E 0x00000400
  190. #define TR_33_PIO_RECOVERY_MASK 0x000003e0
  191. #define TR_33_PIO_RECOVERY_SHIFT 5
  192. #define TR_33_PIO_ACCESS_MASK 0x0000001f
  193. #define TR_33_PIO_ACCESS_SHIFT 0
  194. /*
  195. * Interrupt register definitions
  196. */
  197. #define IDE_INTR_DMA 0x80000000
  198. #define IDE_INTR_DEVICE 0x40000000
  199. /*
  200. * FCR Register on Kauai. Not sure what bit 0x4 is ...
  201. */
  202. #define KAUAI_FCR_UATA_MAGIC 0x00000004
  203. #define KAUAI_FCR_UATA_RESET_N 0x00000002
  204. #define KAUAI_FCR_UATA_ENABLE 0x00000001
  205. #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
  206. /* Rounded Multiword DMA timings
  207. *
  208. * I gave up finding a generic formula for all controller
  209. * types and instead, built tables based on timing values
  210. * used by Apple in Darwin's implementation.
  211. */
  212. struct mdma_timings_t {
  213. int accessTime;
  214. int recoveryTime;
  215. int cycleTime;
  216. };
  217. struct mdma_timings_t mdma_timings_33[] =
  218. {
  219. { 240, 240, 480 },
  220. { 180, 180, 360 },
  221. { 135, 135, 270 },
  222. { 120, 120, 240 },
  223. { 105, 105, 210 },
  224. { 90, 90, 180 },
  225. { 75, 75, 150 },
  226. { 75, 45, 120 },
  227. { 0, 0, 0 }
  228. };
  229. struct mdma_timings_t mdma_timings_33k[] =
  230. {
  231. { 240, 240, 480 },
  232. { 180, 180, 360 },
  233. { 150, 150, 300 },
  234. { 120, 120, 240 },
  235. { 90, 120, 210 },
  236. { 90, 90, 180 },
  237. { 90, 60, 150 },
  238. { 90, 30, 120 },
  239. { 0, 0, 0 }
  240. };
  241. struct mdma_timings_t mdma_timings_66[] =
  242. {
  243. { 240, 240, 480 },
  244. { 180, 180, 360 },
  245. { 135, 135, 270 },
  246. { 120, 120, 240 },
  247. { 105, 105, 210 },
  248. { 90, 90, 180 },
  249. { 90, 75, 165 },
  250. { 75, 45, 120 },
  251. { 0, 0, 0 }
  252. };
  253. /* KeyLargo ATA-4 Ultra DMA timings (rounded) */
  254. struct {
  255. int addrSetup; /* ??? */
  256. int rdy2pause;
  257. int wrDataSetup;
  258. } kl66_udma_timings[] =
  259. {
  260. { 0, 180, 120 }, /* Mode 0 */
  261. { 0, 150, 90 }, /* 1 */
  262. { 0, 120, 60 }, /* 2 */
  263. { 0, 90, 45 }, /* 3 */
  264. { 0, 90, 30 } /* 4 */
  265. };
  266. /* UniNorth 2 ATA/100 timings */
  267. struct kauai_timing {
  268. int cycle_time;
  269. u32 timing_reg;
  270. };
  271. static struct kauai_timing kauai_pio_timings[] =
  272. {
  273. { 930 , 0x08000fff },
  274. { 600 , 0x08000a92 },
  275. { 383 , 0x0800060f },
  276. { 360 , 0x08000492 },
  277. { 330 , 0x0800048f },
  278. { 300 , 0x080003cf },
  279. { 270 , 0x080003cc },
  280. { 240 , 0x0800038b },
  281. { 239 , 0x0800030c },
  282. { 180 , 0x05000249 },
  283. { 120 , 0x04000148 },
  284. { 0 , 0 },
  285. };
  286. static struct kauai_timing kauai_mdma_timings[] =
  287. {
  288. { 1260 , 0x00fff000 },
  289. { 480 , 0x00618000 },
  290. { 360 , 0x00492000 },
  291. { 270 , 0x0038e000 },
  292. { 240 , 0x0030c000 },
  293. { 210 , 0x002cb000 },
  294. { 180 , 0x00249000 },
  295. { 150 , 0x00209000 },
  296. { 120 , 0x00148000 },
  297. { 0 , 0 },
  298. };
  299. static struct kauai_timing kauai_udma_timings[] =
  300. {
  301. { 120 , 0x000070c0 },
  302. { 90 , 0x00005d80 },
  303. { 60 , 0x00004a60 },
  304. { 45 , 0x00003a50 },
  305. { 30 , 0x00002a30 },
  306. { 20 , 0x00002921 },
  307. { 0 , 0 },
  308. };
  309. static struct kauai_timing shasta_pio_timings[] =
  310. {
  311. { 930 , 0x08000fff },
  312. { 600 , 0x0A000c97 },
  313. { 383 , 0x07000712 },
  314. { 360 , 0x040003cd },
  315. { 330 , 0x040003cd },
  316. { 300 , 0x040003cd },
  317. { 270 , 0x040003cd },
  318. { 240 , 0x040003cd },
  319. { 239 , 0x040003cd },
  320. { 180 , 0x0400028b },
  321. { 120 , 0x0400010a },
  322. { 0 , 0 },
  323. };
  324. static struct kauai_timing shasta_mdma_timings[] =
  325. {
  326. { 1260 , 0x00fff000 },
  327. { 480 , 0x00820800 },
  328. { 360 , 0x00820800 },
  329. { 270 , 0x00820800 },
  330. { 240 , 0x00820800 },
  331. { 210 , 0x00820800 },
  332. { 180 , 0x00820800 },
  333. { 150 , 0x0028b000 },
  334. { 120 , 0x001ca000 },
  335. { 0 , 0 },
  336. };
  337. static struct kauai_timing shasta_udma133_timings[] =
  338. {
  339. { 120 , 0x00035901, },
  340. { 90 , 0x000348b1, },
  341. { 60 , 0x00033881, },
  342. { 45 , 0x00033861, },
  343. { 30 , 0x00033841, },
  344. { 20 , 0x00033031, },
  345. { 15 , 0x00033021, },
  346. { 0 , 0 },
  347. };
  348. static inline u32
  349. kauai_lookup_timing(struct kauai_timing* table, int cycle_time)
  350. {
  351. int i;
  352. for (i=0; table[i].cycle_time; i++)
  353. if (cycle_time > table[i+1].cycle_time)
  354. return table[i].timing_reg;
  355. BUG();
  356. return 0;
  357. }
  358. /* allow up to 256 DBDMA commands per xfer */
  359. #define MAX_DCMDS 256
  360. /*
  361. * Wait 1s for disk to answer on IDE bus after a hard reset
  362. * of the device (via GPIO/FCR).
  363. *
  364. * Some devices seem to "pollute" the bus even after dropping
  365. * the BSY bit (typically some combo drives slave on the UDMA
  366. * bus) after a hard reset. Since we hard reset all drives on
  367. * KeyLargo ATA66, we have to keep that delay around. I may end
  368. * up not hard resetting anymore on these and keep the delay only
  369. * for older interfaces instead (we have to reset when coming
  370. * from MacOS...) --BenH.
  371. */
  372. #define IDE_WAKEUP_DELAY (1*HZ)
  373. static int pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif);
  374. static int pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq);
  375. static void pmac_ide_selectproc(ide_drive_t *drive);
  376. static void pmac_ide_kauai_selectproc(ide_drive_t *drive);
  377. #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
  378. #define PMAC_IDE_REG(x) \
  379. ((void __iomem *)((drive)->hwif->io_ports[IDE_DATA_OFFSET] + (x)))
  380. /*
  381. * Apply the timings of the proper unit (master/slave) to the shared
  382. * timing register when selecting that unit. This version is for
  383. * ASICs with a single timing register
  384. */
  385. static void
  386. pmac_ide_selectproc(ide_drive_t *drive)
  387. {
  388. pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
  389. if (pmif == NULL)
  390. return;
  391. if (drive->select.b.unit & 0x01)
  392. writel(pmif->timings[1], PMAC_IDE_REG(IDE_TIMING_CONFIG));
  393. else
  394. writel(pmif->timings[0], PMAC_IDE_REG(IDE_TIMING_CONFIG));
  395. (void)readl(PMAC_IDE_REG(IDE_TIMING_CONFIG));
  396. }
  397. /*
  398. * Apply the timings of the proper unit (master/slave) to the shared
  399. * timing register when selecting that unit. This version is for
  400. * ASICs with a dual timing register (Kauai)
  401. */
  402. static void
  403. pmac_ide_kauai_selectproc(ide_drive_t *drive)
  404. {
  405. pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
  406. if (pmif == NULL)
  407. return;
  408. if (drive->select.b.unit & 0x01) {
  409. writel(pmif->timings[1], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
  410. writel(pmif->timings[3], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG));
  411. } else {
  412. writel(pmif->timings[0], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
  413. writel(pmif->timings[2], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG));
  414. }
  415. (void)readl(PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
  416. }
  417. /*
  418. * Force an update of controller timing values for a given drive
  419. */
  420. static void
  421. pmac_ide_do_update_timings(ide_drive_t *drive)
  422. {
  423. pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
  424. if (pmif == NULL)
  425. return;
  426. if (pmif->kind == controller_sh_ata6 ||
  427. pmif->kind == controller_un_ata6 ||
  428. pmif->kind == controller_k2_ata6)
  429. pmac_ide_kauai_selectproc(drive);
  430. else
  431. pmac_ide_selectproc(drive);
  432. }
  433. static void
  434. pmac_outbsync(ide_drive_t *drive, u8 value, unsigned long port)
  435. {
  436. u32 tmp;
  437. writeb(value, (void __iomem *) port);
  438. tmp = readl(PMAC_IDE_REG(IDE_TIMING_CONFIG));
  439. }
  440. /*
  441. * Old tuning functions (called on hdparm -p), sets up drive PIO timings
  442. */
  443. static void
  444. pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
  445. {
  446. u32 *timings, t;
  447. unsigned accessTicks, recTicks;
  448. unsigned accessTime, recTime;
  449. pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
  450. unsigned int cycle_time;
  451. if (pmif == NULL)
  452. return;
  453. /* which drive is it ? */
  454. timings = &pmif->timings[drive->select.b.unit & 0x01];
  455. t = *timings;
  456. cycle_time = ide_pio_cycle_time(drive, pio);
  457. switch (pmif->kind) {
  458. case controller_sh_ata6: {
  459. /* 133Mhz cell */
  460. u32 tr = kauai_lookup_timing(shasta_pio_timings, cycle_time);
  461. t = (t & ~TR_133_PIOREG_PIO_MASK) | tr;
  462. break;
  463. }
  464. case controller_un_ata6:
  465. case controller_k2_ata6: {
  466. /* 100Mhz cell */
  467. u32 tr = kauai_lookup_timing(kauai_pio_timings, cycle_time);
  468. t = (t & ~TR_100_PIOREG_PIO_MASK) | tr;
  469. break;
  470. }
  471. case controller_kl_ata4:
  472. /* 66Mhz cell */
  473. recTime = cycle_time - ide_pio_timings[pio].active_time
  474. - ide_pio_timings[pio].setup_time;
  475. recTime = max(recTime, 150U);
  476. accessTime = ide_pio_timings[pio].active_time;
  477. accessTime = max(accessTime, 150U);
  478. accessTicks = SYSCLK_TICKS_66(accessTime);
  479. accessTicks = min(accessTicks, 0x1fU);
  480. recTicks = SYSCLK_TICKS_66(recTime);
  481. recTicks = min(recTicks, 0x1fU);
  482. t = (t & ~TR_66_PIO_MASK) |
  483. (accessTicks << TR_66_PIO_ACCESS_SHIFT) |
  484. (recTicks << TR_66_PIO_RECOVERY_SHIFT);
  485. break;
  486. default: {
  487. /* 33Mhz cell */
  488. int ebit = 0;
  489. recTime = cycle_time - ide_pio_timings[pio].active_time
  490. - ide_pio_timings[pio].setup_time;
  491. recTime = max(recTime, 150U);
  492. accessTime = ide_pio_timings[pio].active_time;
  493. accessTime = max(accessTime, 150U);
  494. accessTicks = SYSCLK_TICKS(accessTime);
  495. accessTicks = min(accessTicks, 0x1fU);
  496. accessTicks = max(accessTicks, 4U);
  497. recTicks = SYSCLK_TICKS(recTime);
  498. recTicks = min(recTicks, 0x1fU);
  499. recTicks = max(recTicks, 5U) - 4;
  500. if (recTicks > 9) {
  501. recTicks--; /* guess, but it's only for PIO0, so... */
  502. ebit = 1;
  503. }
  504. t = (t & ~TR_33_PIO_MASK) |
  505. (accessTicks << TR_33_PIO_ACCESS_SHIFT) |
  506. (recTicks << TR_33_PIO_RECOVERY_SHIFT);
  507. if (ebit)
  508. t |= TR_33_PIO_E;
  509. break;
  510. }
  511. }
  512. #ifdef IDE_PMAC_DEBUG
  513. printk(KERN_ERR "%s: Set PIO timing for mode %d, reg: 0x%08x\n",
  514. drive->name, pio, *timings);
  515. #endif
  516. *timings = t;
  517. pmac_ide_do_update_timings(drive);
  518. }
  519. #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
  520. /*
  521. * Calculate KeyLargo ATA/66 UDMA timings
  522. */
  523. static int
  524. set_timings_udma_ata4(u32 *timings, u8 speed)
  525. {
  526. unsigned rdyToPauseTicks, wrDataSetupTicks, addrTicks;
  527. if (speed > XFER_UDMA_4)
  528. return 1;
  529. rdyToPauseTicks = SYSCLK_TICKS_66(kl66_udma_timings[speed & 0xf].rdy2pause);
  530. wrDataSetupTicks = SYSCLK_TICKS_66(kl66_udma_timings[speed & 0xf].wrDataSetup);
  531. addrTicks = SYSCLK_TICKS_66(kl66_udma_timings[speed & 0xf].addrSetup);
  532. *timings = ((*timings) & ~(TR_66_UDMA_MASK | TR_66_MDMA_MASK)) |
  533. (wrDataSetupTicks << TR_66_UDMA_WRDATASETUP_SHIFT) |
  534. (rdyToPauseTicks << TR_66_UDMA_RDY2PAUS_SHIFT) |
  535. (addrTicks <<TR_66_UDMA_ADDRSETUP_SHIFT) |
  536. TR_66_UDMA_EN;
  537. #ifdef IDE_PMAC_DEBUG
  538. printk(KERN_ERR "ide_pmac: Set UDMA timing for mode %d, reg: 0x%08x\n",
  539. speed & 0xf, *timings);
  540. #endif
  541. return 0;
  542. }
  543. /*
  544. * Calculate Kauai ATA/100 UDMA timings
  545. */
  546. static int
  547. set_timings_udma_ata6(u32 *pio_timings, u32 *ultra_timings, u8 speed)
  548. {
  549. struct ide_timing *t = ide_timing_find_mode(speed);
  550. u32 tr;
  551. if (speed > XFER_UDMA_5 || t == NULL)
  552. return 1;
  553. tr = kauai_lookup_timing(kauai_udma_timings, (int)t->udma);
  554. *ultra_timings = ((*ultra_timings) & ~TR_100_UDMAREG_UDMA_MASK) | tr;
  555. *ultra_timings = (*ultra_timings) | TR_100_UDMAREG_UDMA_EN;
  556. return 0;
  557. }
  558. /*
  559. * Calculate Shasta ATA/133 UDMA timings
  560. */
  561. static int
  562. set_timings_udma_shasta(u32 *pio_timings, u32 *ultra_timings, u8 speed)
  563. {
  564. struct ide_timing *t = ide_timing_find_mode(speed);
  565. u32 tr;
  566. if (speed > XFER_UDMA_6 || t == NULL)
  567. return 1;
  568. tr = kauai_lookup_timing(shasta_udma133_timings, (int)t->udma);
  569. *ultra_timings = ((*ultra_timings) & ~TR_133_UDMAREG_UDMA_MASK) | tr;
  570. *ultra_timings = (*ultra_timings) | TR_133_UDMAREG_UDMA_EN;
  571. return 0;
  572. }
  573. /*
  574. * Calculate MDMA timings for all cells
  575. */
  576. static void
  577. set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2,
  578. u8 speed)
  579. {
  580. int cycleTime, accessTime = 0, recTime = 0;
  581. unsigned accessTicks, recTicks;
  582. struct hd_driveid *id = drive->id;
  583. struct mdma_timings_t* tm = NULL;
  584. int i;
  585. /* Get default cycle time for mode */
  586. switch(speed & 0xf) {
  587. case 0: cycleTime = 480; break;
  588. case 1: cycleTime = 150; break;
  589. case 2: cycleTime = 120; break;
  590. default:
  591. BUG();
  592. break;
  593. }
  594. /* Check if drive provides explicit DMA cycle time */
  595. if ((id->field_valid & 2) && id->eide_dma_time)
  596. cycleTime = max_t(int, id->eide_dma_time, cycleTime);
  597. /* OHare limits according to some old Apple sources */
  598. if ((intf_type == controller_ohare) && (cycleTime < 150))
  599. cycleTime = 150;
  600. /* Get the proper timing array for this controller */
  601. switch(intf_type) {
  602. case controller_sh_ata6:
  603. case controller_un_ata6:
  604. case controller_k2_ata6:
  605. break;
  606. case controller_kl_ata4:
  607. tm = mdma_timings_66;
  608. break;
  609. case controller_kl_ata3:
  610. tm = mdma_timings_33k;
  611. break;
  612. default:
  613. tm = mdma_timings_33;
  614. break;
  615. }
  616. if (tm != NULL) {
  617. /* Lookup matching access & recovery times */
  618. i = -1;
  619. for (;;) {
  620. if (tm[i+1].cycleTime < cycleTime)
  621. break;
  622. i++;
  623. }
  624. cycleTime = tm[i].cycleTime;
  625. accessTime = tm[i].accessTime;
  626. recTime = tm[i].recoveryTime;
  627. #ifdef IDE_PMAC_DEBUG
  628. printk(KERN_ERR "%s: MDMA, cycleTime: %d, accessTime: %d, recTime: %d\n",
  629. drive->name, cycleTime, accessTime, recTime);
  630. #endif
  631. }
  632. switch(intf_type) {
  633. case controller_sh_ata6: {
  634. /* 133Mhz cell */
  635. u32 tr = kauai_lookup_timing(shasta_mdma_timings, cycleTime);
  636. *timings = ((*timings) & ~TR_133_PIOREG_MDMA_MASK) | tr;
  637. *timings2 = (*timings2) & ~TR_133_UDMAREG_UDMA_EN;
  638. }
  639. case controller_un_ata6:
  640. case controller_k2_ata6: {
  641. /* 100Mhz cell */
  642. u32 tr = kauai_lookup_timing(kauai_mdma_timings, cycleTime);
  643. *timings = ((*timings) & ~TR_100_PIOREG_MDMA_MASK) | tr;
  644. *timings2 = (*timings2) & ~TR_100_UDMAREG_UDMA_EN;
  645. }
  646. break;
  647. case controller_kl_ata4:
  648. /* 66Mhz cell */
  649. accessTicks = SYSCLK_TICKS_66(accessTime);
  650. accessTicks = min(accessTicks, 0x1fU);
  651. accessTicks = max(accessTicks, 0x1U);
  652. recTicks = SYSCLK_TICKS_66(recTime);
  653. recTicks = min(recTicks, 0x1fU);
  654. recTicks = max(recTicks, 0x3U);
  655. /* Clear out mdma bits and disable udma */
  656. *timings = ((*timings) & ~(TR_66_MDMA_MASK | TR_66_UDMA_MASK)) |
  657. (accessTicks << TR_66_MDMA_ACCESS_SHIFT) |
  658. (recTicks << TR_66_MDMA_RECOVERY_SHIFT);
  659. break;
  660. case controller_kl_ata3:
  661. /* 33Mhz cell on KeyLargo */
  662. accessTicks = SYSCLK_TICKS(accessTime);
  663. accessTicks = max(accessTicks, 1U);
  664. accessTicks = min(accessTicks, 0x1fU);
  665. accessTime = accessTicks * IDE_SYSCLK_NS;
  666. recTicks = SYSCLK_TICKS(recTime);
  667. recTicks = max(recTicks, 1U);
  668. recTicks = min(recTicks, 0x1fU);
  669. *timings = ((*timings) & ~TR_33_MDMA_MASK) |
  670. (accessTicks << TR_33_MDMA_ACCESS_SHIFT) |
  671. (recTicks << TR_33_MDMA_RECOVERY_SHIFT);
  672. break;
  673. default: {
  674. /* 33Mhz cell on others */
  675. int halfTick = 0;
  676. int origAccessTime = accessTime;
  677. int origRecTime = recTime;
  678. accessTicks = SYSCLK_TICKS(accessTime);
  679. accessTicks = max(accessTicks, 1U);
  680. accessTicks = min(accessTicks, 0x1fU);
  681. accessTime = accessTicks * IDE_SYSCLK_NS;
  682. recTicks = SYSCLK_TICKS(recTime);
  683. recTicks = max(recTicks, 2U) - 1;
  684. recTicks = min(recTicks, 0x1fU);
  685. recTime = (recTicks + 1) * IDE_SYSCLK_NS;
  686. if ((accessTicks > 1) &&
  687. ((accessTime - IDE_SYSCLK_NS/2) >= origAccessTime) &&
  688. ((recTime - IDE_SYSCLK_NS/2) >= origRecTime)) {
  689. halfTick = 1;
  690. accessTicks--;
  691. }
  692. *timings = ((*timings) & ~TR_33_MDMA_MASK) |
  693. (accessTicks << TR_33_MDMA_ACCESS_SHIFT) |
  694. (recTicks << TR_33_MDMA_RECOVERY_SHIFT);
  695. if (halfTick)
  696. *timings |= TR_33_MDMA_HALFTICK;
  697. }
  698. }
  699. #ifdef IDE_PMAC_DEBUG
  700. printk(KERN_ERR "%s: Set MDMA timing for mode %d, reg: 0x%08x\n",
  701. drive->name, speed & 0xf, *timings);
  702. #endif
  703. }
  704. #endif /* #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC */
  705. static void pmac_ide_set_dma_mode(ide_drive_t *drive, const u8 speed)
  706. {
  707. int unit = (drive->select.b.unit & 0x01);
  708. int ret = 0;
  709. pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
  710. u32 *timings, *timings2, tl[2];
  711. timings = &pmif->timings[unit];
  712. timings2 = &pmif->timings[unit+2];
  713. /* Copy timings to local image */
  714. tl[0] = *timings;
  715. tl[1] = *timings2;
  716. #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
  717. if (speed >= XFER_UDMA_0) {
  718. if (pmif->kind == controller_kl_ata4)
  719. ret = set_timings_udma_ata4(&tl[0], speed);
  720. else if (pmif->kind == controller_un_ata6
  721. || pmif->kind == controller_k2_ata6)
  722. ret = set_timings_udma_ata6(&tl[0], &tl[1], speed);
  723. else if (pmif->kind == controller_sh_ata6)
  724. ret = set_timings_udma_shasta(&tl[0], &tl[1], speed);
  725. else
  726. ret = -1;
  727. } else
  728. set_timings_mdma(drive, pmif->kind, &tl[0], &tl[1], speed);
  729. #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
  730. if (ret)
  731. return;
  732. /* Apply timings to controller */
  733. *timings = tl[0];
  734. *timings2 = tl[1];
  735. pmac_ide_do_update_timings(drive);
  736. }
  737. /*
  738. * Blast some well known "safe" values to the timing registers at init or
  739. * wakeup from sleep time, before we do real calculation
  740. */
  741. static void
  742. sanitize_timings(pmac_ide_hwif_t *pmif)
  743. {
  744. unsigned int value, value2 = 0;
  745. switch(pmif->kind) {
  746. case controller_sh_ata6:
  747. value = 0x0a820c97;
  748. value2 = 0x00033031;
  749. break;
  750. case controller_un_ata6:
  751. case controller_k2_ata6:
  752. value = 0x08618a92;
  753. value2 = 0x00002921;
  754. break;
  755. case controller_kl_ata4:
  756. value = 0x0008438c;
  757. break;
  758. case controller_kl_ata3:
  759. value = 0x00084526;
  760. break;
  761. case controller_heathrow:
  762. case controller_ohare:
  763. default:
  764. value = 0x00074526;
  765. break;
  766. }
  767. pmif->timings[0] = pmif->timings[1] = value;
  768. pmif->timings[2] = pmif->timings[3] = value2;
  769. }
  770. /* Suspend call back, should be called after the child devices
  771. * have actually been suspended
  772. */
  773. static int
  774. pmac_ide_do_suspend(ide_hwif_t *hwif)
  775. {
  776. pmac_ide_hwif_t *pmif = (pmac_ide_hwif_t *)hwif->hwif_data;
  777. /* We clear the timings */
  778. pmif->timings[0] = 0;
  779. pmif->timings[1] = 0;
  780. disable_irq(pmif->irq);
  781. /* The media bay will handle itself just fine */
  782. if (pmif->mediabay)
  783. return 0;
  784. /* Kauai has bus control FCRs directly here */
  785. if (pmif->kauai_fcr) {
  786. u32 fcr = readl(pmif->kauai_fcr);
  787. fcr &= ~(KAUAI_FCR_UATA_RESET_N | KAUAI_FCR_UATA_ENABLE);
  788. writel(fcr, pmif->kauai_fcr);
  789. }
  790. /* Disable the bus on older machines and the cell on kauai */
  791. ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, pmif->node, pmif->aapl_bus_id,
  792. 0);
  793. return 0;
  794. }
  795. /* Resume call back, should be called before the child devices
  796. * are resumed
  797. */
  798. static int
  799. pmac_ide_do_resume(ide_hwif_t *hwif)
  800. {
  801. pmac_ide_hwif_t *pmif = (pmac_ide_hwif_t *)hwif->hwif_data;
  802. /* Hard reset & re-enable controller (do we really need to reset ? -BenH) */
  803. if (!pmif->mediabay) {
  804. ppc_md.feature_call(PMAC_FTR_IDE_RESET, pmif->node, pmif->aapl_bus_id, 1);
  805. ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, pmif->node, pmif->aapl_bus_id, 1);
  806. msleep(10);
  807. ppc_md.feature_call(PMAC_FTR_IDE_RESET, pmif->node, pmif->aapl_bus_id, 0);
  808. /* Kauai has it different */
  809. if (pmif->kauai_fcr) {
  810. u32 fcr = readl(pmif->kauai_fcr);
  811. fcr |= KAUAI_FCR_UATA_RESET_N | KAUAI_FCR_UATA_ENABLE;
  812. writel(fcr, pmif->kauai_fcr);
  813. }
  814. msleep(jiffies_to_msecs(IDE_WAKEUP_DELAY));
  815. }
  816. /* Sanitize drive timings */
  817. sanitize_timings(pmif);
  818. enable_irq(pmif->irq);
  819. return 0;
  820. }
  821. static const struct ide_port_info pmac_port_info = {
  822. .chipset = ide_pmac,
  823. .host_flags = IDE_HFLAG_SET_PIO_MODE_KEEP_DMA |
  824. IDE_HFLAG_POST_SET_MODE |
  825. IDE_HFLAG_NO_DMA | /* no SFF-style DMA */
  826. IDE_HFLAG_UNMASK_IRQS,
  827. .pio_mask = ATA_PIO4,
  828. .mwdma_mask = ATA_MWDMA2,
  829. };
  830. /*
  831. * Setup, register & probe an IDE channel driven by this driver, this is
  832. * called by one of the 2 probe functions (macio or PCI). Note that a channel
  833. * that ends up beeing free of any device is not kept around by this driver
  834. * (it is kept in 2.4). This introduce an interface numbering change on some
  835. * rare machines unfortunately, but it's better this way.
  836. */
  837. static int __devinit
  838. pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif, hw_regs_t *hw)
  839. {
  840. struct device_node *np = pmif->node;
  841. const int *bidp;
  842. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  843. struct ide_port_info d = pmac_port_info;
  844. pmif->cable_80 = 0;
  845. pmif->broken_dma = pmif->broken_dma_warn = 0;
  846. if (of_device_is_compatible(np, "shasta-ata")) {
  847. pmif->kind = controller_sh_ata6;
  848. d.udma_mask = ATA_UDMA6;
  849. } else if (of_device_is_compatible(np, "kauai-ata")) {
  850. pmif->kind = controller_un_ata6;
  851. d.udma_mask = ATA_UDMA5;
  852. } else if (of_device_is_compatible(np, "K2-UATA")) {
  853. pmif->kind = controller_k2_ata6;
  854. d.udma_mask = ATA_UDMA5;
  855. } else if (of_device_is_compatible(np, "keylargo-ata")) {
  856. if (strcmp(np->name, "ata-4") == 0) {
  857. pmif->kind = controller_kl_ata4;
  858. d.udma_mask = ATA_UDMA4;
  859. } else
  860. pmif->kind = controller_kl_ata3;
  861. } else if (of_device_is_compatible(np, "heathrow-ata")) {
  862. pmif->kind = controller_heathrow;
  863. } else {
  864. pmif->kind = controller_ohare;
  865. pmif->broken_dma = 1;
  866. }
  867. bidp = of_get_property(np, "AAPL,bus-id", NULL);
  868. pmif->aapl_bus_id = bidp ? *bidp : 0;
  869. /* Get cable type from device-tree */
  870. if (pmif->kind == controller_kl_ata4 || pmif->kind == controller_un_ata6
  871. || pmif->kind == controller_k2_ata6
  872. || pmif->kind == controller_sh_ata6) {
  873. const char* cable = of_get_property(np, "cable-type", NULL);
  874. if (cable && !strncmp(cable, "80-", 3))
  875. pmif->cable_80 = 1;
  876. }
  877. /* G5's seem to have incorrect cable type in device-tree. Let's assume
  878. * they have a 80 conductor cable, this seem to be always the case unless
  879. * the user mucked around
  880. */
  881. if (of_device_is_compatible(np, "K2-UATA") ||
  882. of_device_is_compatible(np, "shasta-ata"))
  883. pmif->cable_80 = 1;
  884. /* On Kauai-type controllers, we make sure the FCR is correct */
  885. if (pmif->kauai_fcr)
  886. writel(KAUAI_FCR_UATA_MAGIC |
  887. KAUAI_FCR_UATA_RESET_N |
  888. KAUAI_FCR_UATA_ENABLE, pmif->kauai_fcr);
  889. pmif->mediabay = 0;
  890. /* Make sure we have sane timings */
  891. sanitize_timings(pmif);
  892. #ifndef CONFIG_PPC64
  893. /* XXX FIXME: Media bay stuff need re-organizing */
  894. if (np->parent && np->parent->name
  895. && strcasecmp(np->parent->name, "media-bay") == 0) {
  896. #ifdef CONFIG_PMAC_MEDIABAY
  897. media_bay_set_ide_infos(np->parent, pmif->regbase, pmif->irq,
  898. hwif);
  899. #endif /* CONFIG_PMAC_MEDIABAY */
  900. pmif->mediabay = 1;
  901. if (!bidp)
  902. pmif->aapl_bus_id = 1;
  903. } else if (pmif->kind == controller_ohare) {
  904. /* The code below is having trouble on some ohare machines
  905. * (timing related ?). Until I can put my hand on one of these
  906. * units, I keep the old way
  907. */
  908. ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, np, 0, 1);
  909. } else
  910. #endif
  911. {
  912. /* This is necessary to enable IDE when net-booting */
  913. ppc_md.feature_call(PMAC_FTR_IDE_RESET, np, pmif->aapl_bus_id, 1);
  914. ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, np, pmif->aapl_bus_id, 1);
  915. msleep(10);
  916. ppc_md.feature_call(PMAC_FTR_IDE_RESET, np, pmif->aapl_bus_id, 0);
  917. msleep(jiffies_to_msecs(IDE_WAKEUP_DELAY));
  918. }
  919. /* Setup MMIO ops */
  920. default_hwif_mmiops(hwif);
  921. hwif->OUTBSYNC = pmac_outbsync;
  922. /* Tell common code _not_ to mess with resources */
  923. hwif->mmio = 1;
  924. hwif->hwif_data = pmif;
  925. ide_init_port_hw(hwif, hw);
  926. hwif->noprobe = pmif->mediabay;
  927. hwif->cbl = pmif->cable_80 ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
  928. hwif->set_pio_mode = pmac_ide_set_pio_mode;
  929. if (pmif->kind == controller_un_ata6
  930. || pmif->kind == controller_k2_ata6
  931. || pmif->kind == controller_sh_ata6)
  932. hwif->selectproc = pmac_ide_kauai_selectproc;
  933. else
  934. hwif->selectproc = pmac_ide_selectproc;
  935. hwif->set_dma_mode = pmac_ide_set_dma_mode;
  936. printk(KERN_INFO "ide%d: Found Apple %s controller, bus ID %d%s, irq %d\n",
  937. hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
  938. pmif->mediabay ? " (mediabay)" : "", hwif->irq);
  939. #ifdef CONFIG_PMAC_MEDIABAY
  940. if (pmif->mediabay && check_media_bay_by_base(pmif->regbase, MB_CD) == 0)
  941. hwif->noprobe = 0;
  942. #endif /* CONFIG_PMAC_MEDIABAY */
  943. #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
  944. if (pmif->cable_80 == 0)
  945. d.udma_mask &= ATA_UDMA2;
  946. /* has a DBDMA controller channel */
  947. if (pmif->dma_regs == 0 || pmac_ide_setup_dma(pmif, hwif) < 0)
  948. #endif
  949. d.udma_mask = d.mwdma_mask = 0;
  950. idx[0] = hwif->index;
  951. ide_device_add(idx, &d);
  952. return 0;
  953. }
  954. static void __devinit pmac_ide_init_ports(hw_regs_t *hw, unsigned long base)
  955. {
  956. int i;
  957. for (i = 0; i < 8; ++i)
  958. hw->io_ports[i] = base + i * 0x10;
  959. hw->io_ports[8] = base + 0x160;
  960. }
  961. /*
  962. * Attach to a macio probed interface
  963. */
  964. static int __devinit
  965. pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
  966. {
  967. void __iomem *base;
  968. unsigned long regbase;
  969. ide_hwif_t *hwif;
  970. pmac_ide_hwif_t *pmif;
  971. int irq, rc;
  972. hw_regs_t hw;
  973. pmif = kzalloc(sizeof(*pmif), GFP_KERNEL);
  974. if (pmif == NULL)
  975. return -ENOMEM;
  976. hwif = ide_find_port();
  977. if (hwif == NULL) {
  978. printk(KERN_ERR "ide-pmac: MacIO interface attach with no slot\n");
  979. printk(KERN_ERR " %s\n", mdev->ofdev.node->full_name);
  980. rc = -ENODEV;
  981. goto out_free_pmif;
  982. }
  983. if (macio_resource_count(mdev) == 0) {
  984. printk(KERN_WARNING "ide-pmac: no address for %s\n",
  985. mdev->ofdev.node->full_name);
  986. rc = -ENXIO;
  987. goto out_free_pmif;
  988. }
  989. /* Request memory resource for IO ports */
  990. if (macio_request_resource(mdev, 0, "ide-pmac (ports)")) {
  991. printk(KERN_ERR "ide-pmac: can't request MMIO resource for "
  992. "%s!\n", mdev->ofdev.node->full_name);
  993. rc = -EBUSY;
  994. goto out_free_pmif;
  995. }
  996. /* XXX This is bogus. Should be fixed in the registry by checking
  997. * the kind of host interrupt controller, a bit like gatwick
  998. * fixes in irq.c. That works well enough for the single case
  999. * where that happens though...
  1000. */
  1001. if (macio_irq_count(mdev) == 0) {
  1002. printk(KERN_WARNING "ide-pmac: no intrs for device %s, using "
  1003. "13\n", mdev->ofdev.node->full_name);
  1004. irq = irq_create_mapping(NULL, 13);
  1005. } else
  1006. irq = macio_irq(mdev, 0);
  1007. base = ioremap(macio_resource_start(mdev, 0), 0x400);
  1008. regbase = (unsigned long) base;
  1009. hwif->dev = &mdev->bus->pdev->dev;
  1010. pmif->mdev = mdev;
  1011. pmif->node = mdev->ofdev.node;
  1012. pmif->regbase = regbase;
  1013. pmif->irq = irq;
  1014. pmif->kauai_fcr = NULL;
  1015. #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
  1016. if (macio_resource_count(mdev) >= 2) {
  1017. if (macio_request_resource(mdev, 1, "ide-pmac (dma)"))
  1018. printk(KERN_WARNING "ide-pmac: can't request DMA "
  1019. "resource for %s!\n",
  1020. mdev->ofdev.node->full_name);
  1021. else
  1022. pmif->dma_regs = ioremap(macio_resource_start(mdev, 1), 0x1000);
  1023. } else
  1024. pmif->dma_regs = NULL;
  1025. #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
  1026. dev_set_drvdata(&mdev->ofdev.dev, hwif);
  1027. memset(&hw, 0, sizeof(hw));
  1028. pmac_ide_init_ports(&hw, pmif->regbase);
  1029. hw.irq = irq;
  1030. hw.dev = &mdev->ofdev.dev;
  1031. rc = pmac_ide_setup_device(pmif, hwif, &hw);
  1032. if (rc != 0) {
  1033. /* The inteface is released to the common IDE layer */
  1034. dev_set_drvdata(&mdev->ofdev.dev, NULL);
  1035. iounmap(base);
  1036. if (pmif->dma_regs) {
  1037. iounmap(pmif->dma_regs);
  1038. macio_release_resource(mdev, 1);
  1039. }
  1040. macio_release_resource(mdev, 0);
  1041. kfree(pmif);
  1042. }
  1043. return rc;
  1044. out_free_pmif:
  1045. kfree(pmif);
  1046. return rc;
  1047. }
  1048. static int
  1049. pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t mesg)
  1050. {
  1051. ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
  1052. int rc = 0;
  1053. if (mesg.event != mdev->ofdev.dev.power.power_state.event
  1054. && (mesg.event & PM_EVENT_SLEEP)) {
  1055. rc = pmac_ide_do_suspend(hwif);
  1056. if (rc == 0)
  1057. mdev->ofdev.dev.power.power_state = mesg;
  1058. }
  1059. return rc;
  1060. }
  1061. static int
  1062. pmac_ide_macio_resume(struct macio_dev *mdev)
  1063. {
  1064. ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
  1065. int rc = 0;
  1066. if (mdev->ofdev.dev.power.power_state.event != PM_EVENT_ON) {
  1067. rc = pmac_ide_do_resume(hwif);
  1068. if (rc == 0)
  1069. mdev->ofdev.dev.power.power_state = PMSG_ON;
  1070. }
  1071. return rc;
  1072. }
  1073. /*
  1074. * Attach to a PCI probed interface
  1075. */
  1076. static int __devinit
  1077. pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
  1078. {
  1079. ide_hwif_t *hwif;
  1080. struct device_node *np;
  1081. pmac_ide_hwif_t *pmif;
  1082. void __iomem *base;
  1083. unsigned long rbase, rlen;
  1084. int rc;
  1085. hw_regs_t hw;
  1086. np = pci_device_to_OF_node(pdev);
  1087. if (np == NULL) {
  1088. printk(KERN_ERR "ide-pmac: cannot find MacIO node for Kauai ATA interface\n");
  1089. return -ENODEV;
  1090. }
  1091. pmif = kzalloc(sizeof(*pmif), GFP_KERNEL);
  1092. if (pmif == NULL)
  1093. return -ENOMEM;
  1094. hwif = ide_find_port();
  1095. if (hwif == NULL) {
  1096. printk(KERN_ERR "ide-pmac: PCI interface attach with no slot\n");
  1097. printk(KERN_ERR " %s\n", np->full_name);
  1098. rc = -ENODEV;
  1099. goto out_free_pmif;
  1100. }
  1101. if (pci_enable_device(pdev)) {
  1102. printk(KERN_WARNING "ide-pmac: Can't enable PCI device for "
  1103. "%s\n", np->full_name);
  1104. rc = -ENXIO;
  1105. goto out_free_pmif;
  1106. }
  1107. pci_set_master(pdev);
  1108. if (pci_request_regions(pdev, "Kauai ATA")) {
  1109. printk(KERN_ERR "ide-pmac: Cannot obtain PCI resources for "
  1110. "%s\n", np->full_name);
  1111. rc = -ENXIO;
  1112. goto out_free_pmif;
  1113. }
  1114. hwif->dev = &pdev->dev;
  1115. pmif->mdev = NULL;
  1116. pmif->node = np;
  1117. rbase = pci_resource_start(pdev, 0);
  1118. rlen = pci_resource_len(pdev, 0);
  1119. base = ioremap(rbase, rlen);
  1120. pmif->regbase = (unsigned long) base + 0x2000;
  1121. #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
  1122. pmif->dma_regs = base + 0x1000;
  1123. #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
  1124. pmif->kauai_fcr = base;
  1125. pmif->irq = pdev->irq;
  1126. pci_set_drvdata(pdev, hwif);
  1127. memset(&hw, 0, sizeof(hw));
  1128. pmac_ide_init_ports(&hw, pmif->regbase);
  1129. hw.irq = pdev->irq;
  1130. hw.dev = &pdev->dev;
  1131. rc = pmac_ide_setup_device(pmif, hwif, &hw);
  1132. if (rc != 0) {
  1133. /* The inteface is released to the common IDE layer */
  1134. pci_set_drvdata(pdev, NULL);
  1135. iounmap(base);
  1136. pci_release_regions(pdev);
  1137. kfree(pmif);
  1138. }
  1139. return rc;
  1140. out_free_pmif:
  1141. kfree(pmif);
  1142. return rc;
  1143. }
  1144. static int
  1145. pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
  1146. {
  1147. ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev);
  1148. int rc = 0;
  1149. if (mesg.event != pdev->dev.power.power_state.event
  1150. && (mesg.event & PM_EVENT_SLEEP)) {
  1151. rc = pmac_ide_do_suspend(hwif);
  1152. if (rc == 0)
  1153. pdev->dev.power.power_state = mesg;
  1154. }
  1155. return rc;
  1156. }
  1157. static int
  1158. pmac_ide_pci_resume(struct pci_dev *pdev)
  1159. {
  1160. ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev);
  1161. int rc = 0;
  1162. if (pdev->dev.power.power_state.event != PM_EVENT_ON) {
  1163. rc = pmac_ide_do_resume(hwif);
  1164. if (rc == 0)
  1165. pdev->dev.power.power_state = PMSG_ON;
  1166. }
  1167. return rc;
  1168. }
  1169. static struct of_device_id pmac_ide_macio_match[] =
  1170. {
  1171. {
  1172. .name = "IDE",
  1173. },
  1174. {
  1175. .name = "ATA",
  1176. },
  1177. {
  1178. .type = "ide",
  1179. },
  1180. {
  1181. .type = "ata",
  1182. },
  1183. {},
  1184. };
  1185. static struct macio_driver pmac_ide_macio_driver =
  1186. {
  1187. .name = "ide-pmac",
  1188. .match_table = pmac_ide_macio_match,
  1189. .probe = pmac_ide_macio_attach,
  1190. .suspend = pmac_ide_macio_suspend,
  1191. .resume = pmac_ide_macio_resume,
  1192. };
  1193. static const struct pci_device_id pmac_ide_pci_match[] = {
  1194. { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_UNI_N_ATA), 0 },
  1195. { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_IPID_ATA100), 0 },
  1196. { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_K2_ATA100), 0 },
  1197. { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_SH_ATA), 0 },
  1198. { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_IPID2_ATA), 0 },
  1199. {},
  1200. };
  1201. static struct pci_driver pmac_ide_pci_driver = {
  1202. .name = "ide-pmac",
  1203. .id_table = pmac_ide_pci_match,
  1204. .probe = pmac_ide_pci_attach,
  1205. .suspend = pmac_ide_pci_suspend,
  1206. .resume = pmac_ide_pci_resume,
  1207. };
  1208. MODULE_DEVICE_TABLE(pci, pmac_ide_pci_match);
  1209. int __init pmac_ide_probe(void)
  1210. {
  1211. int error;
  1212. if (!machine_is(powermac))
  1213. return -ENODEV;
  1214. #ifdef CONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST
  1215. error = pci_register_driver(&pmac_ide_pci_driver);
  1216. if (error)
  1217. goto out;
  1218. error = macio_register_driver(&pmac_ide_macio_driver);
  1219. if (error) {
  1220. pci_unregister_driver(&pmac_ide_pci_driver);
  1221. goto out;
  1222. }
  1223. #else
  1224. error = macio_register_driver(&pmac_ide_macio_driver);
  1225. if (error)
  1226. goto out;
  1227. error = pci_register_driver(&pmac_ide_pci_driver);
  1228. if (error) {
  1229. macio_unregister_driver(&pmac_ide_macio_driver);
  1230. goto out;
  1231. }
  1232. #endif
  1233. out:
  1234. return error;
  1235. }
  1236. #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
  1237. /*
  1238. * pmac_ide_build_dmatable builds the DBDMA command list
  1239. * for a transfer and sets the DBDMA channel to point to it.
  1240. */
  1241. static int
  1242. pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
  1243. {
  1244. struct dbdma_cmd *table;
  1245. int i, count = 0;
  1246. ide_hwif_t *hwif = HWIF(drive);
  1247. pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)hwif->hwif_data;
  1248. volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
  1249. struct scatterlist *sg;
  1250. int wr = (rq_data_dir(rq) == WRITE);
  1251. /* DMA table is already aligned */
  1252. table = (struct dbdma_cmd *) pmif->dma_table_cpu;
  1253. /* Make sure DMA controller is stopped (necessary ?) */
  1254. writel((RUN|PAUSE|FLUSH|WAKE|DEAD) << 16, &dma->control);
  1255. while (readl(&dma->status) & RUN)
  1256. udelay(1);
  1257. hwif->sg_nents = i = ide_build_sglist(drive, rq);
  1258. if (!i)
  1259. return 0;
  1260. /* Build DBDMA commands list */
  1261. sg = hwif->sg_table;
  1262. while (i && sg_dma_len(sg)) {
  1263. u32 cur_addr;
  1264. u32 cur_len;
  1265. cur_addr = sg_dma_address(sg);
  1266. cur_len = sg_dma_len(sg);
  1267. if (pmif->broken_dma && cur_addr & (L1_CACHE_BYTES - 1)) {
  1268. if (pmif->broken_dma_warn == 0) {
  1269. printk(KERN_WARNING "%s: DMA on non aligned address, "
  1270. "switching to PIO on Ohare chipset\n", drive->name);
  1271. pmif->broken_dma_warn = 1;
  1272. }
  1273. goto use_pio_instead;
  1274. }
  1275. while (cur_len) {
  1276. unsigned int tc = (cur_len < 0xfe00)? cur_len: 0xfe00;
  1277. if (count++ >= MAX_DCMDS) {
  1278. printk(KERN_WARNING "%s: DMA table too small\n",
  1279. drive->name);
  1280. goto use_pio_instead;
  1281. }
  1282. st_le16(&table->command, wr? OUTPUT_MORE: INPUT_MORE);
  1283. st_le16(&table->req_count, tc);
  1284. st_le32(&table->phy_addr, cur_addr);
  1285. table->cmd_dep = 0;
  1286. table->xfer_status = 0;
  1287. table->res_count = 0;
  1288. cur_addr += tc;
  1289. cur_len -= tc;
  1290. ++table;
  1291. }
  1292. sg = sg_next(sg);
  1293. i--;
  1294. }
  1295. /* convert the last command to an input/output last command */
  1296. if (count) {
  1297. st_le16(&table[-1].command, wr? OUTPUT_LAST: INPUT_LAST);
  1298. /* add the stop command to the end of the list */
  1299. memset(table, 0, sizeof(struct dbdma_cmd));
  1300. st_le16(&table->command, DBDMA_STOP);
  1301. mb();
  1302. writel(hwif->dmatable_dma, &dma->cmdptr);
  1303. return 1;
  1304. }
  1305. printk(KERN_DEBUG "%s: empty DMA table?\n", drive->name);
  1306. use_pio_instead:
  1307. ide_destroy_dmatable(drive);
  1308. return 0; /* revert to PIO for this request */
  1309. }
  1310. /* Teardown mappings after DMA has completed. */
  1311. static void
  1312. pmac_ide_destroy_dmatable (ide_drive_t *drive)
  1313. {
  1314. ide_hwif_t *hwif = drive->hwif;
  1315. if (hwif->sg_nents) {
  1316. ide_destroy_dmatable(drive);
  1317. hwif->sg_nents = 0;
  1318. }
  1319. }
  1320. /*
  1321. * Prepare a DMA transfer. We build the DMA table, adjust the timings for
  1322. * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion
  1323. */
  1324. static int
  1325. pmac_ide_dma_setup(ide_drive_t *drive)
  1326. {
  1327. ide_hwif_t *hwif = HWIF(drive);
  1328. pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)hwif->hwif_data;
  1329. struct request *rq = HWGROUP(drive)->rq;
  1330. u8 unit = (drive->select.b.unit & 0x01);
  1331. u8 ata4;
  1332. if (pmif == NULL)
  1333. return 1;
  1334. ata4 = (pmif->kind == controller_kl_ata4);
  1335. if (!pmac_ide_build_dmatable(drive, rq)) {
  1336. ide_map_sg(drive, rq);
  1337. return 1;
  1338. }
  1339. /* Apple adds 60ns to wrDataSetup on reads */
  1340. if (ata4 && (pmif->timings[unit] & TR_66_UDMA_EN)) {
  1341. writel(pmif->timings[unit] + (!rq_data_dir(rq) ? 0x00800000UL : 0),
  1342. PMAC_IDE_REG(IDE_TIMING_CONFIG));
  1343. (void)readl(PMAC_IDE_REG(IDE_TIMING_CONFIG));
  1344. }
  1345. drive->waiting_for_dma = 1;
  1346. return 0;
  1347. }
  1348. static void
  1349. pmac_ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
  1350. {
  1351. /* issue cmd to drive */
  1352. ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, NULL);
  1353. }
  1354. /*
  1355. * Kick the DMA controller into life after the DMA command has been issued
  1356. * to the drive.
  1357. */
  1358. static void
  1359. pmac_ide_dma_start(ide_drive_t *drive)
  1360. {
  1361. pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
  1362. volatile struct dbdma_regs __iomem *dma;
  1363. dma = pmif->dma_regs;
  1364. writel((RUN << 16) | RUN, &dma->control);
  1365. /* Make sure it gets to the controller right now */
  1366. (void)readl(&dma->control);
  1367. }
  1368. /*
  1369. * After a DMA transfer, make sure the controller is stopped
  1370. */
  1371. static int
  1372. pmac_ide_dma_end (ide_drive_t *drive)
  1373. {
  1374. pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
  1375. volatile struct dbdma_regs __iomem *dma;
  1376. u32 dstat;
  1377. if (pmif == NULL)
  1378. return 0;
  1379. dma = pmif->dma_regs;
  1380. drive->waiting_for_dma = 0;
  1381. dstat = readl(&dma->status);
  1382. writel(((RUN|WAKE|DEAD) << 16), &dma->control);
  1383. pmac_ide_destroy_dmatable(drive);
  1384. /* verify good dma status. we don't check for ACTIVE beeing 0. We should...
  1385. * in theory, but with ATAPI decices doing buffer underruns, that would
  1386. * cause us to disable DMA, which isn't what we want
  1387. */
  1388. return (dstat & (RUN|DEAD)) != RUN;
  1389. }
  1390. /*
  1391. * Check out that the interrupt we got was for us. We can't always know this
  1392. * for sure with those Apple interfaces (well, we could on the recent ones but
  1393. * that's not implemented yet), on the other hand, we don't have shared interrupts
  1394. * so it's not really a problem
  1395. */
  1396. static int
  1397. pmac_ide_dma_test_irq (ide_drive_t *drive)
  1398. {
  1399. pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
  1400. volatile struct dbdma_regs __iomem *dma;
  1401. unsigned long status, timeout;
  1402. if (pmif == NULL)
  1403. return 0;
  1404. dma = pmif->dma_regs;
  1405. /* We have to things to deal with here:
  1406. *
  1407. * - The dbdma won't stop if the command was started
  1408. * but completed with an error without transferring all
  1409. * datas. This happens when bad blocks are met during
  1410. * a multi-block transfer.
  1411. *
  1412. * - The dbdma fifo hasn't yet finished flushing to
  1413. * to system memory when the disk interrupt occurs.
  1414. *
  1415. */
  1416. /* If ACTIVE is cleared, the STOP command have passed and
  1417. * transfer is complete.
  1418. */
  1419. status = readl(&dma->status);
  1420. if (!(status & ACTIVE))
  1421. return 1;
  1422. if (!drive->waiting_for_dma)
  1423. printk(KERN_WARNING "ide%d, ide_dma_test_irq \
  1424. called while not waiting\n", HWIF(drive)->index);
  1425. /* If dbdma didn't execute the STOP command yet, the
  1426. * active bit is still set. We consider that we aren't
  1427. * sharing interrupts (which is hopefully the case with
  1428. * those controllers) and so we just try to flush the
  1429. * channel for pending data in the fifo
  1430. */
  1431. udelay(1);
  1432. writel((FLUSH << 16) | FLUSH, &dma->control);
  1433. timeout = 0;
  1434. for (;;) {
  1435. udelay(1);
  1436. status = readl(&dma->status);
  1437. if ((status & FLUSH) == 0)
  1438. break;
  1439. if (++timeout > 100) {
  1440. printk(KERN_WARNING "ide%d, ide_dma_test_irq \
  1441. timeout flushing channel\n", HWIF(drive)->index);
  1442. break;
  1443. }
  1444. }
  1445. return 1;
  1446. }
  1447. static void pmac_ide_dma_host_set(ide_drive_t *drive, int on)
  1448. {
  1449. }
  1450. static void
  1451. pmac_ide_dma_lost_irq (ide_drive_t *drive)
  1452. {
  1453. pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
  1454. volatile struct dbdma_regs __iomem *dma;
  1455. unsigned long status;
  1456. if (pmif == NULL)
  1457. return;
  1458. dma = pmif->dma_regs;
  1459. status = readl(&dma->status);
  1460. printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status);
  1461. }
  1462. /*
  1463. * Allocate the data structures needed for using DMA with an interface
  1464. * and fill the proper list of functions pointers
  1465. */
  1466. static int __devinit pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
  1467. {
  1468. struct pci_dev *dev = to_pci_dev(hwif->dev);
  1469. /* We won't need pci_dev if we switch to generic consistent
  1470. * DMA routines ...
  1471. */
  1472. if (dev == NULL)
  1473. return -ENODEV;
  1474. /*
  1475. * Allocate space for the DBDMA commands.
  1476. * The +2 is +1 for the stop command and +1 to allow for
  1477. * aligning the start address to a multiple of 16 bytes.
  1478. */
  1479. pmif->dma_table_cpu = (struct dbdma_cmd*)pci_alloc_consistent(
  1480. dev,
  1481. (MAX_DCMDS + 2) * sizeof(struct dbdma_cmd),
  1482. &hwif->dmatable_dma);
  1483. if (pmif->dma_table_cpu == NULL) {
  1484. printk(KERN_ERR "%s: unable to allocate DMA command list\n",
  1485. hwif->name);
  1486. return -ENOMEM;
  1487. }
  1488. hwif->sg_max_nents = MAX_DCMDS;
  1489. hwif->dma_host_set = &pmac_ide_dma_host_set;
  1490. hwif->dma_setup = &pmac_ide_dma_setup;
  1491. hwif->dma_exec_cmd = &pmac_ide_dma_exec_cmd;
  1492. hwif->dma_start = &pmac_ide_dma_start;
  1493. hwif->ide_dma_end = &pmac_ide_dma_end;
  1494. hwif->ide_dma_test_irq = &pmac_ide_dma_test_irq;
  1495. hwif->dma_timeout = &ide_dma_timeout;
  1496. hwif->dma_lost_irq = &pmac_ide_dma_lost_irq;
  1497. return 0;
  1498. }
  1499. #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
  1500. module_init(pmac_ide_probe);
  1501. MODULE_LICENSE("GPL");