ata_piix.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. /*
  2. * ata_piix.c - Intel PATA/SATA controllers
  3. *
  4. * Maintained by: Jeff Garzik <jgarzik@pobox.com>
  5. * Please ALWAYS copy linux-ide@vger.kernel.org
  6. * on emails.
  7. *
  8. *
  9. * Copyright 2003-2005 Red Hat Inc
  10. * Copyright 2003-2005 Jeff Garzik
  11. *
  12. *
  13. * Copyright header from piix.c:
  14. *
  15. * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer
  16. * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
  17. * Copyright (C) 2003 Red Hat Inc
  18. *
  19. *
  20. * This program is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation; either version 2, or (at your option)
  23. * any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; see the file COPYING. If not, write to
  32. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  33. *
  34. *
  35. * libata documentation is available via 'make {ps|pdf}docs',
  36. * as Documentation/DocBook/libata.*
  37. *
  38. * Hardware documentation available at http://developer.intel.com/
  39. *
  40. * Documentation
  41. * Publicly available from Intel web site. Errata documentation
  42. * is also publicly available. As an aide to anyone hacking on this
  43. * driver the list of errata that are relevant is below, going back to
  44. * PIIX4. Older device documentation is now a bit tricky to find.
  45. *
  46. * The chipsets all follow very much the same design. The original Triton
  47. * series chipsets do _not_ support independent device timings, but this
  48. * is fixed in Triton II. With the odd mobile exception the chips then
  49. * change little except in gaining more modes until SATA arrives. This
  50. * driver supports only the chips with independent timing (that is those
  51. * with SITRE and the 0x44 timing register). See pata_oldpiix and pata_mpiix
  52. * for the early chip drivers.
  53. *
  54. * Errata of note:
  55. *
  56. * Unfixable
  57. * PIIX4 errata #9 - Only on ultra obscure hw
  58. * ICH3 errata #13 - Not observed to affect real hw
  59. * by Intel
  60. *
  61. * Things we must deal with
  62. * PIIX4 errata #10 - BM IDE hang with non UDMA
  63. * (must stop/start dma to recover)
  64. * 440MX errata #15 - As PIIX4 errata #10
  65. * PIIX4 errata #15 - Must not read control registers
  66. * during a PIO transfer
  67. * 440MX errata #13 - As PIIX4 errata #15
  68. * ICH2 errata #21 - DMA mode 0 doesn't work right
  69. * ICH0/1 errata #55 - As ICH2 errata #21
  70. * ICH2 spec c #9 - Extra operations needed to handle
  71. * drive hotswap [NOT YET SUPPORTED]
  72. * ICH2 spec c #20 - IDE PRD must not cross a 64K boundary
  73. * and must be dword aligned
  74. * ICH2 spec c #24 - UDMA mode 4,5 t85/86 should be 6ns not 3.3
  75. * ICH7 errata #16 - MWDMA1 timings are incorrect
  76. *
  77. * Should have been BIOS fixed:
  78. * 450NX: errata #19 - DMA hangs on old 450NX
  79. * 450NX: errata #20 - DMA hangs on old 450NX
  80. * 450NX: errata #25 - Corruption with DMA on old 450NX
  81. * ICH3 errata #15 - IDE deadlock under high load
  82. * (BIOS must set dev 31 fn 0 bit 23)
  83. * ICH3 errata #18 - Don't use native mode
  84. */
  85. #include <linux/kernel.h>
  86. #include <linux/module.h>
  87. #include <linux/pci.h>
  88. #include <linux/init.h>
  89. #include <linux/blkdev.h>
  90. #include <linux/delay.h>
  91. #include <linux/device.h>
  92. #include <linux/gfp.h>
  93. #include <scsi/scsi_host.h>
  94. #include <linux/libata.h>
  95. #include <linux/dmi.h>
  96. #define DRV_NAME "ata_piix"
  97. #define DRV_VERSION "2.13"
  98. enum {
  99. PIIX_IOCFG = 0x54, /* IDE I/O configuration register */
  100. ICH5_PMR = 0x90, /* port mapping register */
  101. ICH5_PCS = 0x92, /* port control and status */
  102. PIIX_SIDPR_BAR = 5,
  103. PIIX_SIDPR_LEN = 16,
  104. PIIX_SIDPR_IDX = 0,
  105. PIIX_SIDPR_DATA = 4,
  106. PIIX_FLAG_CHECKINTR = (1 << 28), /* make sure PCI INTx enabled */
  107. PIIX_FLAG_SIDPR = (1 << 29), /* SATA idx/data pair regs */
  108. PIIX_PATA_FLAGS = ATA_FLAG_SLAVE_POSS,
  109. PIIX_SATA_FLAGS = ATA_FLAG_SATA | PIIX_FLAG_CHECKINTR,
  110. PIIX_FLAG_PIO16 = (1 << 30), /*support 16bit PIO only*/
  111. PIIX_80C_PRI = (1 << 5) | (1 << 4),
  112. PIIX_80C_SEC = (1 << 7) | (1 << 6),
  113. /* constants for mapping table */
  114. P0 = 0, /* port 0 */
  115. P1 = 1, /* port 1 */
  116. P2 = 2, /* port 2 */
  117. P3 = 3, /* port 3 */
  118. IDE = -1, /* IDE */
  119. NA = -2, /* not available */
  120. RV = -3, /* reserved */
  121. PIIX_AHCI_DEVICE = 6,
  122. /* host->flags bits */
  123. PIIX_HOST_BROKEN_SUSPEND = (1 << 24),
  124. };
  125. enum piix_controller_ids {
  126. /* controller IDs */
  127. piix_pata_mwdma, /* PIIX3 MWDMA only */
  128. piix_pata_33, /* PIIX4 at 33Mhz */
  129. ich_pata_33, /* ICH up to UDMA 33 only */
  130. ich_pata_66, /* ICH up to 66 Mhz */
  131. ich_pata_100, /* ICH up to UDMA 100 */
  132. ich_pata_100_nomwdma1, /* ICH up to UDMA 100 but with no MWDMA1*/
  133. ich5_sata,
  134. ich6_sata,
  135. ich6m_sata,
  136. ich8_sata,
  137. ich8_2port_sata,
  138. ich8m_apple_sata, /* locks up on second port enable */
  139. tolapai_sata,
  140. piix_pata_vmw, /* PIIX4 for VMware, spurious DMA_ERR */
  141. ich8_sata_snb,
  142. };
  143. struct piix_map_db {
  144. const u32 mask;
  145. const u16 port_enable;
  146. const int map[][4];
  147. };
  148. struct piix_host_priv {
  149. const int *map;
  150. u32 saved_iocfg;
  151. void __iomem *sidpr;
  152. };
  153. static int piix_init_one(struct pci_dev *pdev,
  154. const struct pci_device_id *ent);
  155. static void piix_remove_one(struct pci_dev *pdev);
  156. static int piix_pata_prereset(struct ata_link *link, unsigned long deadline);
  157. static void piix_set_piomode(struct ata_port *ap, struct ata_device *adev);
  158. static void piix_set_dmamode(struct ata_port *ap, struct ata_device *adev);
  159. static void ich_set_dmamode(struct ata_port *ap, struct ata_device *adev);
  160. static int ich_pata_cable_detect(struct ata_port *ap);
  161. static u8 piix_vmw_bmdma_status(struct ata_port *ap);
  162. static int piix_sidpr_scr_read(struct ata_link *link,
  163. unsigned int reg, u32 *val);
  164. static int piix_sidpr_scr_write(struct ata_link *link,
  165. unsigned int reg, u32 val);
  166. static int piix_sidpr_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
  167. unsigned hints);
  168. static bool piix_irq_check(struct ata_port *ap);
  169. static int piix_port_start(struct ata_port *ap);
  170. #ifdef CONFIG_PM
  171. static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
  172. static int piix_pci_device_resume(struct pci_dev *pdev);
  173. #endif
  174. static unsigned int in_module_init = 1;
  175. static const struct pci_device_id piix_pci_tbl[] = {
  176. /* Intel PIIX3 for the 430HX etc */
  177. { 0x8086, 0x7010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_mwdma },
  178. /* VMware ICH4 */
  179. { 0x8086, 0x7111, 0x15ad, 0x1976, 0, 0, piix_pata_vmw },
  180. /* Intel PIIX4 for the 430TX/440BX/MX chipset: UDMA 33 */
  181. /* Also PIIX4E (fn3 rev 2) and PIIX4M (fn3 rev 3) */
  182. { 0x8086, 0x7111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
  183. /* Intel PIIX4 */
  184. { 0x8086, 0x7199, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
  185. /* Intel PIIX4 */
  186. { 0x8086, 0x7601, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
  187. /* Intel PIIX */
  188. { 0x8086, 0x84CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
  189. /* Intel ICH (i810, i815, i840) UDMA 66*/
  190. { 0x8086, 0x2411, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_66 },
  191. /* Intel ICH0 : UDMA 33*/
  192. { 0x8086, 0x2421, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_33 },
  193. /* Intel ICH2M */
  194. { 0x8086, 0x244A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  195. /* Intel ICH2 (i810E2, i845, 850, 860) UDMA 100 */
  196. { 0x8086, 0x244B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  197. /* Intel ICH3M */
  198. { 0x8086, 0x248A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  199. /* Intel ICH3 (E7500/1) UDMA 100 */
  200. { 0x8086, 0x248B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  201. /* Intel ICH4-L */
  202. { 0x8086, 0x24C1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  203. /* Intel ICH4 (i845GV, i845E, i852, i855) UDMA 100 */
  204. { 0x8086, 0x24CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  205. { 0x8086, 0x24CB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  206. /* Intel ICH5 */
  207. { 0x8086, 0x24DB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  208. /* C-ICH (i810E2) */
  209. { 0x8086, 0x245B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  210. /* ESB (855GME/875P + 6300ESB) UDMA 100 */
  211. { 0x8086, 0x25A2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  212. /* ICH6 (and 6) (i915) UDMA 100 */
  213. { 0x8086, 0x266F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  214. /* ICH7/7-R (i945, i975) UDMA 100*/
  215. { 0x8086, 0x27DF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100_nomwdma1 },
  216. { 0x8086, 0x269E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100_nomwdma1 },
  217. /* ICH8 Mobile PATA Controller */
  218. { 0x8086, 0x2850, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  219. /* SATA ports */
  220. /* 82801EB (ICH5) */
  221. { 0x8086, 0x24d1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  222. /* 82801EB (ICH5) */
  223. { 0x8086, 0x24df, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  224. /* 6300ESB (ICH5 variant with broken PCS present bits) */
  225. { 0x8086, 0x25a3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  226. /* 6300ESB pretending RAID */
  227. { 0x8086, 0x25b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  228. /* 82801FB/FW (ICH6/ICH6W) */
  229. { 0x8086, 0x2651, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata },
  230. /* 82801FR/FRW (ICH6R/ICH6RW) */
  231. { 0x8086, 0x2652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata },
  232. /* 82801FBM ICH6M (ICH6R with only port 0 and 2 implemented).
  233. * Attach iff the controller is in IDE mode. */
  234. { 0x8086, 0x2653, PCI_ANY_ID, PCI_ANY_ID,
  235. PCI_CLASS_STORAGE_IDE << 8, 0xffff00, ich6m_sata },
  236. /* 82801GB/GR/GH (ICH7, identical to ICH6) */
  237. { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata },
  238. /* 2801GBM/GHM (ICH7M, identical to ICH6M) */
  239. { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6m_sata },
  240. /* Enterprise Southbridge 2 (631xESB/632xESB) */
  241. { 0x8086, 0x2680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata },
  242. /* SATA Controller 1 IDE (ICH8) */
  243. { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
  244. /* SATA Controller 2 IDE (ICH8) */
  245. { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  246. /* Mobile SATA Controller IDE (ICH8M), Apple */
  247. { 0x8086, 0x2828, 0x106b, 0x00a0, 0, 0, ich8m_apple_sata },
  248. { 0x8086, 0x2828, 0x106b, 0x00a1, 0, 0, ich8m_apple_sata },
  249. { 0x8086, 0x2828, 0x106b, 0x00a3, 0, 0, ich8m_apple_sata },
  250. /* Mobile SATA Controller IDE (ICH8M) */
  251. { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
  252. /* SATA Controller IDE (ICH9) */
  253. { 0x8086, 0x2920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
  254. /* SATA Controller IDE (ICH9) */
  255. { 0x8086, 0x2921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  256. /* SATA Controller IDE (ICH9) */
  257. { 0x8086, 0x2926, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  258. /* SATA Controller IDE (ICH9M) */
  259. { 0x8086, 0x2928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  260. /* SATA Controller IDE (ICH9M) */
  261. { 0x8086, 0x292d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  262. /* SATA Controller IDE (ICH9M) */
  263. { 0x8086, 0x292e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
  264. /* SATA Controller IDE (Tolapai) */
  265. { 0x8086, 0x5028, PCI_ANY_ID, PCI_ANY_ID, 0, 0, tolapai_sata },
  266. /* SATA Controller IDE (ICH10) */
  267. { 0x8086, 0x3a00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
  268. /* SATA Controller IDE (ICH10) */
  269. { 0x8086, 0x3a06, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  270. /* SATA Controller IDE (ICH10) */
  271. { 0x8086, 0x3a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
  272. /* SATA Controller IDE (ICH10) */
  273. { 0x8086, 0x3a26, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  274. /* SATA Controller IDE (PCH) */
  275. { 0x8086, 0x3b20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
  276. /* SATA Controller IDE (PCH) */
  277. { 0x8086, 0x3b21, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  278. /* SATA Controller IDE (PCH) */
  279. { 0x8086, 0x3b26, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  280. /* SATA Controller IDE (PCH) */
  281. { 0x8086, 0x3b28, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
  282. /* SATA Controller IDE (PCH) */
  283. { 0x8086, 0x3b2d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  284. /* SATA Controller IDE (PCH) */
  285. { 0x8086, 0x3b2e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
  286. /* SATA Controller IDE (CPT) */
  287. { 0x8086, 0x1c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_snb },
  288. /* SATA Controller IDE (CPT) */
  289. { 0x8086, 0x1c01, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_snb },
  290. /* SATA Controller IDE (CPT) */
  291. { 0x8086, 0x1c08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  292. /* SATA Controller IDE (CPT) */
  293. { 0x8086, 0x1c09, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  294. /* SATA Controller IDE (PBG) */
  295. { 0x8086, 0x1d00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_snb },
  296. /* SATA Controller IDE (PBG) */
  297. { 0x8086, 0x1d08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  298. /* SATA Controller IDE (Panther Point) */
  299. { 0x8086, 0x1e00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_snb },
  300. /* SATA Controller IDE (Panther Point) */
  301. { 0x8086, 0x1e01, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_snb },
  302. /* SATA Controller IDE (Panther Point) */
  303. { 0x8086, 0x1e08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  304. /* SATA Controller IDE (Panther Point) */
  305. { 0x8086, 0x1e09, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  306. { } /* terminate list */
  307. };
  308. static struct pci_driver piix_pci_driver = {
  309. .name = DRV_NAME,
  310. .id_table = piix_pci_tbl,
  311. .probe = piix_init_one,
  312. .remove = piix_remove_one,
  313. #ifdef CONFIG_PM
  314. .suspend = piix_pci_device_suspend,
  315. .resume = piix_pci_device_resume,
  316. #endif
  317. };
  318. static struct scsi_host_template piix_sht = {
  319. ATA_BMDMA_SHT(DRV_NAME),
  320. };
  321. static struct ata_port_operations piix_sata_ops = {
  322. .inherits = &ata_bmdma32_port_ops,
  323. .sff_irq_check = piix_irq_check,
  324. .port_start = piix_port_start,
  325. };
  326. static struct ata_port_operations piix_pata_ops = {
  327. .inherits = &piix_sata_ops,
  328. .cable_detect = ata_cable_40wire,
  329. .set_piomode = piix_set_piomode,
  330. .set_dmamode = piix_set_dmamode,
  331. .prereset = piix_pata_prereset,
  332. };
  333. static struct ata_port_operations piix_vmw_ops = {
  334. .inherits = &piix_pata_ops,
  335. .bmdma_status = piix_vmw_bmdma_status,
  336. };
  337. static struct ata_port_operations ich_pata_ops = {
  338. .inherits = &piix_pata_ops,
  339. .cable_detect = ich_pata_cable_detect,
  340. .set_dmamode = ich_set_dmamode,
  341. };
  342. static struct device_attribute *piix_sidpr_shost_attrs[] = {
  343. &dev_attr_link_power_management_policy,
  344. NULL
  345. };
  346. static struct scsi_host_template piix_sidpr_sht = {
  347. ATA_BMDMA_SHT(DRV_NAME),
  348. .shost_attrs = piix_sidpr_shost_attrs,
  349. };
  350. static struct ata_port_operations piix_sidpr_sata_ops = {
  351. .inherits = &piix_sata_ops,
  352. .hardreset = sata_std_hardreset,
  353. .scr_read = piix_sidpr_scr_read,
  354. .scr_write = piix_sidpr_scr_write,
  355. .set_lpm = piix_sidpr_set_lpm,
  356. };
  357. static const struct piix_map_db ich5_map_db = {
  358. .mask = 0x7,
  359. .port_enable = 0x3,
  360. .map = {
  361. /* PM PS SM SS MAP */
  362. { P0, NA, P1, NA }, /* 000b */
  363. { P1, NA, P0, NA }, /* 001b */
  364. { RV, RV, RV, RV },
  365. { RV, RV, RV, RV },
  366. { P0, P1, IDE, IDE }, /* 100b */
  367. { P1, P0, IDE, IDE }, /* 101b */
  368. { IDE, IDE, P0, P1 }, /* 110b */
  369. { IDE, IDE, P1, P0 }, /* 111b */
  370. },
  371. };
  372. static const struct piix_map_db ich6_map_db = {
  373. .mask = 0x3,
  374. .port_enable = 0xf,
  375. .map = {
  376. /* PM PS SM SS MAP */
  377. { P0, P2, P1, P3 }, /* 00b */
  378. { IDE, IDE, P1, P3 }, /* 01b */
  379. { P0, P2, IDE, IDE }, /* 10b */
  380. { RV, RV, RV, RV },
  381. },
  382. };
  383. static const struct piix_map_db ich6m_map_db = {
  384. .mask = 0x3,
  385. .port_enable = 0x5,
  386. /* Map 01b isn't specified in the doc but some notebooks use
  387. * it anyway. MAP 01b have been spotted on both ICH6M and
  388. * ICH7M.
  389. */
  390. .map = {
  391. /* PM PS SM SS MAP */
  392. { P0, P2, NA, NA }, /* 00b */
  393. { IDE, IDE, P1, P3 }, /* 01b */
  394. { P0, P2, IDE, IDE }, /* 10b */
  395. { RV, RV, RV, RV },
  396. },
  397. };
  398. static const struct piix_map_db ich8_map_db = {
  399. .mask = 0x3,
  400. .port_enable = 0xf,
  401. .map = {
  402. /* PM PS SM SS MAP */
  403. { P0, P2, P1, P3 }, /* 00b (hardwired when in AHCI) */
  404. { RV, RV, RV, RV },
  405. { P0, P2, IDE, IDE }, /* 10b (IDE mode) */
  406. { RV, RV, RV, RV },
  407. },
  408. };
  409. static const struct piix_map_db ich8_2port_map_db = {
  410. .mask = 0x3,
  411. .port_enable = 0x3,
  412. .map = {
  413. /* PM PS SM SS MAP */
  414. { P0, NA, P1, NA }, /* 00b */
  415. { RV, RV, RV, RV }, /* 01b */
  416. { RV, RV, RV, RV }, /* 10b */
  417. { RV, RV, RV, RV },
  418. },
  419. };
  420. static const struct piix_map_db ich8m_apple_map_db = {
  421. .mask = 0x3,
  422. .port_enable = 0x1,
  423. .map = {
  424. /* PM PS SM SS MAP */
  425. { P0, NA, NA, NA }, /* 00b */
  426. { RV, RV, RV, RV },
  427. { P0, P2, IDE, IDE }, /* 10b */
  428. { RV, RV, RV, RV },
  429. },
  430. };
  431. static const struct piix_map_db tolapai_map_db = {
  432. .mask = 0x3,
  433. .port_enable = 0x3,
  434. .map = {
  435. /* PM PS SM SS MAP */
  436. { P0, NA, P1, NA }, /* 00b */
  437. { RV, RV, RV, RV }, /* 01b */
  438. { RV, RV, RV, RV }, /* 10b */
  439. { RV, RV, RV, RV },
  440. },
  441. };
  442. static const struct piix_map_db *piix_map_db_table[] = {
  443. [ich5_sata] = &ich5_map_db,
  444. [ich6_sata] = &ich6_map_db,
  445. [ich6m_sata] = &ich6m_map_db,
  446. [ich8_sata] = &ich8_map_db,
  447. [ich8_2port_sata] = &ich8_2port_map_db,
  448. [ich8m_apple_sata] = &ich8m_apple_map_db,
  449. [tolapai_sata] = &tolapai_map_db,
  450. [ich8_sata_snb] = &ich8_map_db,
  451. };
  452. static struct ata_port_info piix_port_info[] = {
  453. [piix_pata_mwdma] = /* PIIX3 MWDMA only */
  454. {
  455. .flags = PIIX_PATA_FLAGS,
  456. .pio_mask = ATA_PIO4,
  457. .mwdma_mask = ATA_MWDMA12_ONLY, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
  458. .port_ops = &piix_pata_ops,
  459. },
  460. [piix_pata_33] = /* PIIX4 at 33MHz */
  461. {
  462. .flags = PIIX_PATA_FLAGS,
  463. .pio_mask = ATA_PIO4,
  464. .mwdma_mask = ATA_MWDMA12_ONLY, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
  465. .udma_mask = ATA_UDMA2,
  466. .port_ops = &piix_pata_ops,
  467. },
  468. [ich_pata_33] = /* ICH0 - ICH at 33Mhz*/
  469. {
  470. .flags = PIIX_PATA_FLAGS,
  471. .pio_mask = ATA_PIO4,
  472. .mwdma_mask = ATA_MWDMA12_ONLY, /* Check: maybe MWDMA0 is ok */
  473. .udma_mask = ATA_UDMA2,
  474. .port_ops = &ich_pata_ops,
  475. },
  476. [ich_pata_66] = /* ICH controllers up to 66MHz */
  477. {
  478. .flags = PIIX_PATA_FLAGS,
  479. .pio_mask = ATA_PIO4,
  480. .mwdma_mask = ATA_MWDMA12_ONLY, /* MWDMA0 is broken on chip */
  481. .udma_mask = ATA_UDMA4,
  482. .port_ops = &ich_pata_ops,
  483. },
  484. [ich_pata_100] =
  485. {
  486. .flags = PIIX_PATA_FLAGS | PIIX_FLAG_CHECKINTR,
  487. .pio_mask = ATA_PIO4,
  488. .mwdma_mask = ATA_MWDMA12_ONLY,
  489. .udma_mask = ATA_UDMA5,
  490. .port_ops = &ich_pata_ops,
  491. },
  492. [ich_pata_100_nomwdma1] =
  493. {
  494. .flags = PIIX_PATA_FLAGS | PIIX_FLAG_CHECKINTR,
  495. .pio_mask = ATA_PIO4,
  496. .mwdma_mask = ATA_MWDMA2_ONLY,
  497. .udma_mask = ATA_UDMA5,
  498. .port_ops = &ich_pata_ops,
  499. },
  500. [ich5_sata] =
  501. {
  502. .flags = PIIX_SATA_FLAGS,
  503. .pio_mask = ATA_PIO4,
  504. .mwdma_mask = ATA_MWDMA2,
  505. .udma_mask = ATA_UDMA6,
  506. .port_ops = &piix_sata_ops,
  507. },
  508. [ich6_sata] =
  509. {
  510. .flags = PIIX_SATA_FLAGS,
  511. .pio_mask = ATA_PIO4,
  512. .mwdma_mask = ATA_MWDMA2,
  513. .udma_mask = ATA_UDMA6,
  514. .port_ops = &piix_sata_ops,
  515. },
  516. [ich6m_sata] =
  517. {
  518. .flags = PIIX_SATA_FLAGS,
  519. .pio_mask = ATA_PIO4,
  520. .mwdma_mask = ATA_MWDMA2,
  521. .udma_mask = ATA_UDMA6,
  522. .port_ops = &piix_sata_ops,
  523. },
  524. [ich8_sata] =
  525. {
  526. .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SIDPR,
  527. .pio_mask = ATA_PIO4,
  528. .mwdma_mask = ATA_MWDMA2,
  529. .udma_mask = ATA_UDMA6,
  530. .port_ops = &piix_sata_ops,
  531. },
  532. [ich8_2port_sata] =
  533. {
  534. .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SIDPR,
  535. .pio_mask = ATA_PIO4,
  536. .mwdma_mask = ATA_MWDMA2,
  537. .udma_mask = ATA_UDMA6,
  538. .port_ops = &piix_sata_ops,
  539. },
  540. [tolapai_sata] =
  541. {
  542. .flags = PIIX_SATA_FLAGS,
  543. .pio_mask = ATA_PIO4,
  544. .mwdma_mask = ATA_MWDMA2,
  545. .udma_mask = ATA_UDMA6,
  546. .port_ops = &piix_sata_ops,
  547. },
  548. [ich8m_apple_sata] =
  549. {
  550. .flags = PIIX_SATA_FLAGS,
  551. .pio_mask = ATA_PIO4,
  552. .mwdma_mask = ATA_MWDMA2,
  553. .udma_mask = ATA_UDMA6,
  554. .port_ops = &piix_sata_ops,
  555. },
  556. [piix_pata_vmw] =
  557. {
  558. .flags = PIIX_PATA_FLAGS,
  559. .pio_mask = ATA_PIO4,
  560. .mwdma_mask = ATA_MWDMA12_ONLY, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
  561. .udma_mask = ATA_UDMA2,
  562. .port_ops = &piix_vmw_ops,
  563. },
  564. /*
  565. * some Sandybridge chipsets have broken 32 mode up to now,
  566. * see https://bugzilla.kernel.org/show_bug.cgi?id=40592
  567. */
  568. [ich8_sata_snb] =
  569. {
  570. .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SIDPR | PIIX_FLAG_PIO16,
  571. .pio_mask = ATA_PIO4,
  572. .mwdma_mask = ATA_MWDMA2,
  573. .udma_mask = ATA_UDMA6,
  574. .port_ops = &piix_sata_ops,
  575. },
  576. };
  577. static struct pci_bits piix_enable_bits[] = {
  578. { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
  579. { 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */
  580. };
  581. MODULE_AUTHOR("Andre Hedrick, Alan Cox, Andrzej Krzysztofowicz, Jeff Garzik");
  582. MODULE_DESCRIPTION("SCSI low-level driver for Intel PIIX/ICH ATA controllers");
  583. MODULE_LICENSE("GPL");
  584. MODULE_DEVICE_TABLE(pci, piix_pci_tbl);
  585. MODULE_VERSION(DRV_VERSION);
  586. struct ich_laptop {
  587. u16 device;
  588. u16 subvendor;
  589. u16 subdevice;
  590. };
  591. /*
  592. * List of laptops that use short cables rather than 80 wire
  593. */
  594. static const struct ich_laptop ich_laptop[] = {
  595. /* devid, subvendor, subdev */
  596. { 0x27DF, 0x0005, 0x0280 }, /* ICH7 on Acer 5602WLMi */
  597. { 0x27DF, 0x1025, 0x0102 }, /* ICH7 on Acer 5602aWLMi */
  598. { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */
  599. { 0x27DF, 0x1028, 0x02b0 }, /* ICH7 on unknown Dell */
  600. { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */
  601. { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */
  602. { 0x27DF, 0x103C, 0x361a }, /* ICH7 on unknown HP */
  603. { 0x27DF, 0x1071, 0xD221 }, /* ICH7 on Hercules EC-900 */
  604. { 0x27DF, 0x152D, 0x0778 }, /* ICH7 on unknown Intel */
  605. { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on ACER Aspire 2023WLMi */
  606. { 0x24CA, 0x1025, 0x003d }, /* ICH4 on ACER TM290 */
  607. { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */
  608. { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
  609. { 0x27df, 0x104d, 0x900e }, /* ICH7 on Sony TZ-90 */
  610. /* end marker */
  611. { 0, }
  612. };
  613. static int piix_port_start(struct ata_port *ap)
  614. {
  615. if (!(ap->flags & PIIX_FLAG_PIO16))
  616. ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE;
  617. return ata_bmdma_port_start(ap);
  618. }
  619. /**
  620. * ich_pata_cable_detect - Probe host controller cable detect info
  621. * @ap: Port for which cable detect info is desired
  622. *
  623. * Read 80c cable indicator from ATA PCI device's PCI config
  624. * register. This register is normally set by firmware (BIOS).
  625. *
  626. * LOCKING:
  627. * None (inherited from caller).
  628. */
  629. static int ich_pata_cable_detect(struct ata_port *ap)
  630. {
  631. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  632. struct piix_host_priv *hpriv = ap->host->private_data;
  633. const struct ich_laptop *lap = &ich_laptop[0];
  634. u8 mask;
  635. /* Check for specials - Acer Aspire 5602WLMi */
  636. while (lap->device) {
  637. if (lap->device == pdev->device &&
  638. lap->subvendor == pdev->subsystem_vendor &&
  639. lap->subdevice == pdev->subsystem_device)
  640. return ATA_CBL_PATA40_SHORT;
  641. lap++;
  642. }
  643. /* check BIOS cable detect results */
  644. mask = ap->port_no == 0 ? PIIX_80C_PRI : PIIX_80C_SEC;
  645. if ((hpriv->saved_iocfg & mask) == 0)
  646. return ATA_CBL_PATA40;
  647. return ATA_CBL_PATA80;
  648. }
  649. /**
  650. * piix_pata_prereset - prereset for PATA host controller
  651. * @link: Target link
  652. * @deadline: deadline jiffies for the operation
  653. *
  654. * LOCKING:
  655. * None (inherited from caller).
  656. */
  657. static int piix_pata_prereset(struct ata_link *link, unsigned long deadline)
  658. {
  659. struct ata_port *ap = link->ap;
  660. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  661. if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no]))
  662. return -ENOENT;
  663. return ata_sff_prereset(link, deadline);
  664. }
  665. static DEFINE_SPINLOCK(piix_lock);
  666. static void piix_set_timings(struct ata_port *ap, struct ata_device *adev,
  667. u8 pio)
  668. {
  669. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  670. unsigned long flags;
  671. unsigned int is_slave = (adev->devno != 0);
  672. unsigned int master_port= ap->port_no ? 0x42 : 0x40;
  673. unsigned int slave_port = 0x44;
  674. u16 master_data;
  675. u8 slave_data;
  676. u8 udma_enable;
  677. int control = 0;
  678. /*
  679. * See Intel Document 298600-004 for the timing programing rules
  680. * for ICH controllers.
  681. */
  682. static const /* ISP RTC */
  683. u8 timings[][2] = { { 0, 0 },
  684. { 0, 0 },
  685. { 1, 0 },
  686. { 2, 1 },
  687. { 2, 3 }, };
  688. if (pio >= 2)
  689. control |= 1; /* TIME1 enable */
  690. if (ata_pio_need_iordy(adev))
  691. control |= 2; /* IE enable */
  692. /* Intel specifies that the PPE functionality is for disk only */
  693. if (adev->class == ATA_DEV_ATA)
  694. control |= 4; /* PPE enable */
  695. /*
  696. * If the drive MWDMA is faster than it can do PIO then
  697. * we must force PIO into PIO0
  698. */
  699. if (adev->pio_mode < XFER_PIO_0 + pio)
  700. /* Enable DMA timing only */
  701. control |= 8; /* PIO cycles in PIO0 */
  702. spin_lock_irqsave(&piix_lock, flags);
  703. /* PIO configuration clears DTE unconditionally. It will be
  704. * programmed in set_dmamode which is guaranteed to be called
  705. * after set_piomode if any DMA mode is available.
  706. */
  707. pci_read_config_word(dev, master_port, &master_data);
  708. if (is_slave) {
  709. /* clear TIME1|IE1|PPE1|DTE1 */
  710. master_data &= 0xff0f;
  711. /* enable PPE1, IE1 and TIME1 as needed */
  712. master_data |= (control << 4);
  713. pci_read_config_byte(dev, slave_port, &slave_data);
  714. slave_data &= (ap->port_no ? 0x0f : 0xf0);
  715. /* Load the timing nibble for this slave */
  716. slave_data |= ((timings[pio][0] << 2) | timings[pio][1])
  717. << (ap->port_no ? 4 : 0);
  718. } else {
  719. /* clear ISP|RCT|TIME0|IE0|PPE0|DTE0 */
  720. master_data &= 0xccf0;
  721. /* Enable PPE, IE and TIME as appropriate */
  722. master_data |= control;
  723. /* load ISP and RCT */
  724. master_data |=
  725. (timings[pio][0] << 12) |
  726. (timings[pio][1] << 8);
  727. }
  728. /* Enable SITRE (separate slave timing register) */
  729. master_data |= 0x4000;
  730. pci_write_config_word(dev, master_port, master_data);
  731. if (is_slave)
  732. pci_write_config_byte(dev, slave_port, slave_data);
  733. /* Ensure the UDMA bit is off - it will be turned back on if
  734. UDMA is selected */
  735. if (ap->udma_mask) {
  736. pci_read_config_byte(dev, 0x48, &udma_enable);
  737. udma_enable &= ~(1 << (2 * ap->port_no + adev->devno));
  738. pci_write_config_byte(dev, 0x48, udma_enable);
  739. }
  740. spin_unlock_irqrestore(&piix_lock, flags);
  741. }
  742. /**
  743. * piix_set_piomode - Initialize host controller PATA PIO timings
  744. * @ap: Port whose timings we are configuring
  745. * @adev: Drive in question
  746. *
  747. * Set PIO mode for device, in host controller PCI config space.
  748. *
  749. * LOCKING:
  750. * None (inherited from caller).
  751. */
  752. static void piix_set_piomode(struct ata_port *ap, struct ata_device *adev)
  753. {
  754. piix_set_timings(ap, adev, adev->pio_mode - XFER_PIO_0);
  755. }
  756. /**
  757. * do_pata_set_dmamode - Initialize host controller PATA PIO timings
  758. * @ap: Port whose timings we are configuring
  759. * @adev: Drive in question
  760. * @isich: set if the chip is an ICH device
  761. *
  762. * Set UDMA mode for device, in host controller PCI config space.
  763. *
  764. * LOCKING:
  765. * None (inherited from caller).
  766. */
  767. static void do_pata_set_dmamode(struct ata_port *ap, struct ata_device *adev, int isich)
  768. {
  769. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  770. unsigned long flags;
  771. u8 speed = adev->dma_mode;
  772. int devid = adev->devno + 2 * ap->port_no;
  773. u8 udma_enable = 0;
  774. if (speed >= XFER_UDMA_0) {
  775. unsigned int udma = speed - XFER_UDMA_0;
  776. u16 udma_timing;
  777. u16 ideconf;
  778. int u_clock, u_speed;
  779. spin_lock_irqsave(&piix_lock, flags);
  780. pci_read_config_byte(dev, 0x48, &udma_enable);
  781. /*
  782. * UDMA is handled by a combination of clock switching and
  783. * selection of dividers
  784. *
  785. * Handy rule: Odd modes are UDMATIMx 01, even are 02
  786. * except UDMA0 which is 00
  787. */
  788. u_speed = min(2 - (udma & 1), udma);
  789. if (udma == 5)
  790. u_clock = 0x1000; /* 100Mhz */
  791. else if (udma > 2)
  792. u_clock = 1; /* 66Mhz */
  793. else
  794. u_clock = 0; /* 33Mhz */
  795. udma_enable |= (1 << devid);
  796. /* Load the CT/RP selection */
  797. pci_read_config_word(dev, 0x4A, &udma_timing);
  798. udma_timing &= ~(3 << (4 * devid));
  799. udma_timing |= u_speed << (4 * devid);
  800. pci_write_config_word(dev, 0x4A, udma_timing);
  801. if (isich) {
  802. /* Select a 33/66/100Mhz clock */
  803. pci_read_config_word(dev, 0x54, &ideconf);
  804. ideconf &= ~(0x1001 << devid);
  805. ideconf |= u_clock << devid;
  806. /* For ICH or later we should set bit 10 for better
  807. performance (WR_PingPong_En) */
  808. pci_write_config_word(dev, 0x54, ideconf);
  809. }
  810. pci_write_config_byte(dev, 0x48, udma_enable);
  811. spin_unlock_irqrestore(&piix_lock, flags);
  812. } else {
  813. /* MWDMA is driven by the PIO timings. */
  814. unsigned int mwdma = speed - XFER_MW_DMA_0;
  815. const unsigned int needed_pio[3] = {
  816. XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
  817. };
  818. int pio = needed_pio[mwdma] - XFER_PIO_0;
  819. /* XFER_PIO_0 is never used currently */
  820. piix_set_timings(ap, adev, pio);
  821. }
  822. }
  823. /**
  824. * piix_set_dmamode - Initialize host controller PATA DMA timings
  825. * @ap: Port whose timings we are configuring
  826. * @adev: um
  827. *
  828. * Set MW/UDMA mode for device, in host controller PCI config space.
  829. *
  830. * LOCKING:
  831. * None (inherited from caller).
  832. */
  833. static void piix_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  834. {
  835. do_pata_set_dmamode(ap, adev, 0);
  836. }
  837. /**
  838. * ich_set_dmamode - Initialize host controller PATA DMA timings
  839. * @ap: Port whose timings we are configuring
  840. * @adev: um
  841. *
  842. * Set MW/UDMA mode for device, in host controller PCI config space.
  843. *
  844. * LOCKING:
  845. * None (inherited from caller).
  846. */
  847. static void ich_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  848. {
  849. do_pata_set_dmamode(ap, adev, 1);
  850. }
  851. /*
  852. * Serial ATA Index/Data Pair Superset Registers access
  853. *
  854. * Beginning from ICH8, there's a sane way to access SCRs using index
  855. * and data register pair located at BAR5 which means that we have
  856. * separate SCRs for master and slave. This is handled using libata
  857. * slave_link facility.
  858. */
  859. static const int piix_sidx_map[] = {
  860. [SCR_STATUS] = 0,
  861. [SCR_ERROR] = 2,
  862. [SCR_CONTROL] = 1,
  863. };
  864. static void piix_sidpr_sel(struct ata_link *link, unsigned int reg)
  865. {
  866. struct ata_port *ap = link->ap;
  867. struct piix_host_priv *hpriv = ap->host->private_data;
  868. iowrite32(((ap->port_no * 2 + link->pmp) << 8) | piix_sidx_map[reg],
  869. hpriv->sidpr + PIIX_SIDPR_IDX);
  870. }
  871. static int piix_sidpr_scr_read(struct ata_link *link,
  872. unsigned int reg, u32 *val)
  873. {
  874. struct piix_host_priv *hpriv = link->ap->host->private_data;
  875. if (reg >= ARRAY_SIZE(piix_sidx_map))
  876. return -EINVAL;
  877. piix_sidpr_sel(link, reg);
  878. *val = ioread32(hpriv->sidpr + PIIX_SIDPR_DATA);
  879. return 0;
  880. }
  881. static int piix_sidpr_scr_write(struct ata_link *link,
  882. unsigned int reg, u32 val)
  883. {
  884. struct piix_host_priv *hpriv = link->ap->host->private_data;
  885. if (reg >= ARRAY_SIZE(piix_sidx_map))
  886. return -EINVAL;
  887. piix_sidpr_sel(link, reg);
  888. iowrite32(val, hpriv->sidpr + PIIX_SIDPR_DATA);
  889. return 0;
  890. }
  891. static int piix_sidpr_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
  892. unsigned hints)
  893. {
  894. return sata_link_scr_lpm(link, policy, false);
  895. }
  896. static bool piix_irq_check(struct ata_port *ap)
  897. {
  898. if (unlikely(!ap->ioaddr.bmdma_addr))
  899. return false;
  900. return ap->ops->bmdma_status(ap) & ATA_DMA_INTR;
  901. }
  902. #ifdef CONFIG_PM
  903. static int piix_broken_suspend(void)
  904. {
  905. static const struct dmi_system_id sysids[] = {
  906. {
  907. .ident = "TECRA M3",
  908. .matches = {
  909. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  910. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M3"),
  911. },
  912. },
  913. {
  914. .ident = "TECRA M3",
  915. .matches = {
  916. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  917. DMI_MATCH(DMI_PRODUCT_NAME, "Tecra M3"),
  918. },
  919. },
  920. {
  921. .ident = "TECRA M4",
  922. .matches = {
  923. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  924. DMI_MATCH(DMI_PRODUCT_NAME, "Tecra M4"),
  925. },
  926. },
  927. {
  928. .ident = "TECRA M4",
  929. .matches = {
  930. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  931. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M4"),
  932. },
  933. },
  934. {
  935. .ident = "TECRA M5",
  936. .matches = {
  937. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  938. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M5"),
  939. },
  940. },
  941. {
  942. .ident = "TECRA M6",
  943. .matches = {
  944. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  945. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M6"),
  946. },
  947. },
  948. {
  949. .ident = "TECRA M7",
  950. .matches = {
  951. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  952. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M7"),
  953. },
  954. },
  955. {
  956. .ident = "TECRA A8",
  957. .matches = {
  958. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  959. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A8"),
  960. },
  961. },
  962. {
  963. .ident = "Satellite R20",
  964. .matches = {
  965. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  966. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite R20"),
  967. },
  968. },
  969. {
  970. .ident = "Satellite R25",
  971. .matches = {
  972. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  973. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite R25"),
  974. },
  975. },
  976. {
  977. .ident = "Satellite U200",
  978. .matches = {
  979. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  980. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite U200"),
  981. },
  982. },
  983. {
  984. .ident = "Satellite U200",
  985. .matches = {
  986. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  987. DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE U200"),
  988. },
  989. },
  990. {
  991. .ident = "Satellite Pro U200",
  992. .matches = {
  993. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  994. DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE PRO U200"),
  995. },
  996. },
  997. {
  998. .ident = "Satellite U205",
  999. .matches = {
  1000. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1001. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite U205"),
  1002. },
  1003. },
  1004. {
  1005. .ident = "SATELLITE U205",
  1006. .matches = {
  1007. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1008. DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE U205"),
  1009. },
  1010. },
  1011. {
  1012. .ident = "Portege M500",
  1013. .matches = {
  1014. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1015. DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M500"),
  1016. },
  1017. },
  1018. {
  1019. .ident = "VGN-BX297XP",
  1020. .matches = {
  1021. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  1022. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-BX297XP"),
  1023. },
  1024. },
  1025. { } /* terminate list */
  1026. };
  1027. static const char *oemstrs[] = {
  1028. "Tecra M3,",
  1029. };
  1030. int i;
  1031. if (dmi_check_system(sysids))
  1032. return 1;
  1033. for (i = 0; i < ARRAY_SIZE(oemstrs); i++)
  1034. if (dmi_find_device(DMI_DEV_TYPE_OEM_STRING, oemstrs[i], NULL))
  1035. return 1;
  1036. /* TECRA M4 sometimes forgets its identify and reports bogus
  1037. * DMI information. As the bogus information is a bit
  1038. * generic, match as many entries as possible. This manual
  1039. * matching is necessary because dmi_system_id.matches is
  1040. * limited to four entries.
  1041. */
  1042. if (dmi_match(DMI_SYS_VENDOR, "TOSHIBA") &&
  1043. dmi_match(DMI_PRODUCT_NAME, "000000") &&
  1044. dmi_match(DMI_PRODUCT_VERSION, "000000") &&
  1045. dmi_match(DMI_PRODUCT_SERIAL, "000000") &&
  1046. dmi_match(DMI_BOARD_VENDOR, "TOSHIBA") &&
  1047. dmi_match(DMI_BOARD_NAME, "Portable PC") &&
  1048. dmi_match(DMI_BOARD_VERSION, "Version A0"))
  1049. return 1;
  1050. return 0;
  1051. }
  1052. static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
  1053. {
  1054. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  1055. unsigned long flags;
  1056. int rc = 0;
  1057. rc = ata_host_suspend(host, mesg);
  1058. if (rc)
  1059. return rc;
  1060. /* Some braindamaged ACPI suspend implementations expect the
  1061. * controller to be awake on entry; otherwise, it burns cpu
  1062. * cycles and power trying to do something to the sleeping
  1063. * beauty.
  1064. */
  1065. if (piix_broken_suspend() && (mesg.event & PM_EVENT_SLEEP)) {
  1066. pci_save_state(pdev);
  1067. /* mark its power state as "unknown", since we don't
  1068. * know if e.g. the BIOS will change its device state
  1069. * when we suspend.
  1070. */
  1071. if (pdev->current_state == PCI_D0)
  1072. pdev->current_state = PCI_UNKNOWN;
  1073. /* tell resume that it's waking up from broken suspend */
  1074. spin_lock_irqsave(&host->lock, flags);
  1075. host->flags |= PIIX_HOST_BROKEN_SUSPEND;
  1076. spin_unlock_irqrestore(&host->lock, flags);
  1077. } else
  1078. ata_pci_device_do_suspend(pdev, mesg);
  1079. return 0;
  1080. }
  1081. static int piix_pci_device_resume(struct pci_dev *pdev)
  1082. {
  1083. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  1084. unsigned long flags;
  1085. int rc;
  1086. if (host->flags & PIIX_HOST_BROKEN_SUSPEND) {
  1087. spin_lock_irqsave(&host->lock, flags);
  1088. host->flags &= ~PIIX_HOST_BROKEN_SUSPEND;
  1089. spin_unlock_irqrestore(&host->lock, flags);
  1090. pci_set_power_state(pdev, PCI_D0);
  1091. pci_restore_state(pdev);
  1092. /* PCI device wasn't disabled during suspend. Use
  1093. * pci_reenable_device() to avoid affecting the enable
  1094. * count.
  1095. */
  1096. rc = pci_reenable_device(pdev);
  1097. if (rc)
  1098. dev_err(&pdev->dev,
  1099. "failed to enable device after resume (%d)\n",
  1100. rc);
  1101. } else
  1102. rc = ata_pci_device_do_resume(pdev);
  1103. if (rc == 0)
  1104. ata_host_resume(host);
  1105. return rc;
  1106. }
  1107. #endif
  1108. static u8 piix_vmw_bmdma_status(struct ata_port *ap)
  1109. {
  1110. return ata_bmdma_status(ap) & ~ATA_DMA_ERR;
  1111. }
  1112. #define AHCI_PCI_BAR 5
  1113. #define AHCI_GLOBAL_CTL 0x04
  1114. #define AHCI_ENABLE (1 << 31)
  1115. static int piix_disable_ahci(struct pci_dev *pdev)
  1116. {
  1117. void __iomem *mmio;
  1118. u32 tmp;
  1119. int rc = 0;
  1120. /* BUG: pci_enable_device has not yet been called. This
  1121. * works because this device is usually set up by BIOS.
  1122. */
  1123. if (!pci_resource_start(pdev, AHCI_PCI_BAR) ||
  1124. !pci_resource_len(pdev, AHCI_PCI_BAR))
  1125. return 0;
  1126. mmio = pci_iomap(pdev, AHCI_PCI_BAR, 64);
  1127. if (!mmio)
  1128. return -ENOMEM;
  1129. tmp = ioread32(mmio + AHCI_GLOBAL_CTL);
  1130. if (tmp & AHCI_ENABLE) {
  1131. tmp &= ~AHCI_ENABLE;
  1132. iowrite32(tmp, mmio + AHCI_GLOBAL_CTL);
  1133. tmp = ioread32(mmio + AHCI_GLOBAL_CTL);
  1134. if (tmp & AHCI_ENABLE)
  1135. rc = -EIO;
  1136. }
  1137. pci_iounmap(pdev, mmio);
  1138. return rc;
  1139. }
  1140. /**
  1141. * piix_check_450nx_errata - Check for problem 450NX setup
  1142. * @ata_dev: the PCI device to check
  1143. *
  1144. * Check for the present of 450NX errata #19 and errata #25. If
  1145. * they are found return an error code so we can turn off DMA
  1146. */
  1147. static int __devinit piix_check_450nx_errata(struct pci_dev *ata_dev)
  1148. {
  1149. struct pci_dev *pdev = NULL;
  1150. u16 cfg;
  1151. int no_piix_dma = 0;
  1152. while ((pdev = pci_get_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, pdev)) != NULL) {
  1153. /* Look for 450NX PXB. Check for problem configurations
  1154. A PCI quirk checks bit 6 already */
  1155. pci_read_config_word(pdev, 0x41, &cfg);
  1156. /* Only on the original revision: IDE DMA can hang */
  1157. if (pdev->revision == 0x00)
  1158. no_piix_dma = 1;
  1159. /* On all revisions below 5 PXB bus lock must be disabled for IDE */
  1160. else if (cfg & (1<<14) && pdev->revision < 5)
  1161. no_piix_dma = 2;
  1162. }
  1163. if (no_piix_dma)
  1164. dev_warn(&ata_dev->dev,
  1165. "450NX errata present, disabling IDE DMA%s\n",
  1166. no_piix_dma == 2 ? " - a BIOS update may resolve this"
  1167. : "");
  1168. return no_piix_dma;
  1169. }
  1170. static void __devinit piix_init_pcs(struct ata_host *host,
  1171. const struct piix_map_db *map_db)
  1172. {
  1173. struct pci_dev *pdev = to_pci_dev(host->dev);
  1174. u16 pcs, new_pcs;
  1175. pci_read_config_word(pdev, ICH5_PCS, &pcs);
  1176. new_pcs = pcs | map_db->port_enable;
  1177. if (new_pcs != pcs) {
  1178. DPRINTK("updating PCS from 0x%x to 0x%x\n", pcs, new_pcs);
  1179. pci_write_config_word(pdev, ICH5_PCS, new_pcs);
  1180. msleep(150);
  1181. }
  1182. }
  1183. static const int *__devinit piix_init_sata_map(struct pci_dev *pdev,
  1184. struct ata_port_info *pinfo,
  1185. const struct piix_map_db *map_db)
  1186. {
  1187. const int *map;
  1188. int i, invalid_map = 0;
  1189. u8 map_value;
  1190. pci_read_config_byte(pdev, ICH5_PMR, &map_value);
  1191. map = map_db->map[map_value & map_db->mask];
  1192. dev_info(&pdev->dev, "MAP [");
  1193. for (i = 0; i < 4; i++) {
  1194. switch (map[i]) {
  1195. case RV:
  1196. invalid_map = 1;
  1197. pr_cont(" XX");
  1198. break;
  1199. case NA:
  1200. pr_cont(" --");
  1201. break;
  1202. case IDE:
  1203. WARN_ON((i & 1) || map[i + 1] != IDE);
  1204. pinfo[i / 2] = piix_port_info[ich_pata_100];
  1205. i++;
  1206. pr_cont(" IDE IDE");
  1207. break;
  1208. default:
  1209. pr_cont(" P%d", map[i]);
  1210. if (i & 1)
  1211. pinfo[i / 2].flags |= ATA_FLAG_SLAVE_POSS;
  1212. break;
  1213. }
  1214. }
  1215. pr_cont(" ]\n");
  1216. if (invalid_map)
  1217. dev_err(&pdev->dev, "invalid MAP value %u\n", map_value);
  1218. return map;
  1219. }
  1220. static bool piix_no_sidpr(struct ata_host *host)
  1221. {
  1222. struct pci_dev *pdev = to_pci_dev(host->dev);
  1223. /*
  1224. * Samsung DB-P70 only has three ATA ports exposed and
  1225. * curiously the unconnected first port reports link online
  1226. * while not responding to SRST protocol causing excessive
  1227. * detection delay.
  1228. *
  1229. * Unfortunately, the system doesn't carry enough DMI
  1230. * information to identify the machine but does have subsystem
  1231. * vendor and device set. As it's unclear whether the
  1232. * subsystem vendor/device is used only for this specific
  1233. * board, the port can't be disabled solely with the
  1234. * information; however, turning off SIDPR access works around
  1235. * the problem. Turn it off.
  1236. *
  1237. * This problem is reported in bnc#441240.
  1238. *
  1239. * https://bugzilla.novell.com/show_bug.cgi?id=441420
  1240. */
  1241. if (pdev->vendor == PCI_VENDOR_ID_INTEL && pdev->device == 0x2920 &&
  1242. pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG &&
  1243. pdev->subsystem_device == 0xb049) {
  1244. dev_warn(host->dev,
  1245. "Samsung DB-P70 detected, disabling SIDPR\n");
  1246. return true;
  1247. }
  1248. return false;
  1249. }
  1250. static int __devinit piix_init_sidpr(struct ata_host *host)
  1251. {
  1252. struct pci_dev *pdev = to_pci_dev(host->dev);
  1253. struct piix_host_priv *hpriv = host->private_data;
  1254. struct ata_link *link0 = &host->ports[0]->link;
  1255. u32 scontrol;
  1256. int i, rc;
  1257. /* check for availability */
  1258. for (i = 0; i < 4; i++)
  1259. if (hpriv->map[i] == IDE)
  1260. return 0;
  1261. /* is it blacklisted? */
  1262. if (piix_no_sidpr(host))
  1263. return 0;
  1264. if (!(host->ports[0]->flags & PIIX_FLAG_SIDPR))
  1265. return 0;
  1266. if (pci_resource_start(pdev, PIIX_SIDPR_BAR) == 0 ||
  1267. pci_resource_len(pdev, PIIX_SIDPR_BAR) != PIIX_SIDPR_LEN)
  1268. return 0;
  1269. if (pcim_iomap_regions(pdev, 1 << PIIX_SIDPR_BAR, DRV_NAME))
  1270. return 0;
  1271. hpriv->sidpr = pcim_iomap_table(pdev)[PIIX_SIDPR_BAR];
  1272. /* SCR access via SIDPR doesn't work on some configurations.
  1273. * Give it a test drive by inhibiting power save modes which
  1274. * we'll do anyway.
  1275. */
  1276. piix_sidpr_scr_read(link0, SCR_CONTROL, &scontrol);
  1277. /* if IPM is already 3, SCR access is probably working. Don't
  1278. * un-inhibit power save modes as BIOS might have inhibited
  1279. * them for a reason.
  1280. */
  1281. if ((scontrol & 0xf00) != 0x300) {
  1282. scontrol |= 0x300;
  1283. piix_sidpr_scr_write(link0, SCR_CONTROL, scontrol);
  1284. piix_sidpr_scr_read(link0, SCR_CONTROL, &scontrol);
  1285. if ((scontrol & 0xf00) != 0x300) {
  1286. dev_info(host->dev,
  1287. "SCR access via SIDPR is available but doesn't work\n");
  1288. return 0;
  1289. }
  1290. }
  1291. /* okay, SCRs available, set ops and ask libata for slave_link */
  1292. for (i = 0; i < 2; i++) {
  1293. struct ata_port *ap = host->ports[i];
  1294. ap->ops = &piix_sidpr_sata_ops;
  1295. if (ap->flags & ATA_FLAG_SLAVE_POSS) {
  1296. rc = ata_slave_link_init(ap);
  1297. if (rc)
  1298. return rc;
  1299. }
  1300. }
  1301. return 0;
  1302. }
  1303. static void piix_iocfg_bit18_quirk(struct ata_host *host)
  1304. {
  1305. static const struct dmi_system_id sysids[] = {
  1306. {
  1307. /* Clevo M570U sets IOCFG bit 18 if the cdrom
  1308. * isn't used to boot the system which
  1309. * disables the channel.
  1310. */
  1311. .ident = "M570U",
  1312. .matches = {
  1313. DMI_MATCH(DMI_SYS_VENDOR, "Clevo Co."),
  1314. DMI_MATCH(DMI_PRODUCT_NAME, "M570U"),
  1315. },
  1316. },
  1317. { } /* terminate list */
  1318. };
  1319. struct pci_dev *pdev = to_pci_dev(host->dev);
  1320. struct piix_host_priv *hpriv = host->private_data;
  1321. if (!dmi_check_system(sysids))
  1322. return;
  1323. /* The datasheet says that bit 18 is NOOP but certain systems
  1324. * seem to use it to disable a channel. Clear the bit on the
  1325. * affected systems.
  1326. */
  1327. if (hpriv->saved_iocfg & (1 << 18)) {
  1328. dev_info(&pdev->dev, "applying IOCFG bit18 quirk\n");
  1329. pci_write_config_dword(pdev, PIIX_IOCFG,
  1330. hpriv->saved_iocfg & ~(1 << 18));
  1331. }
  1332. }
  1333. static bool piix_broken_system_poweroff(struct pci_dev *pdev)
  1334. {
  1335. static const struct dmi_system_id broken_systems[] = {
  1336. {
  1337. .ident = "HP Compaq 2510p",
  1338. .matches = {
  1339. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1340. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 2510p"),
  1341. },
  1342. /* PCI slot number of the controller */
  1343. .driver_data = (void *)0x1FUL,
  1344. },
  1345. {
  1346. .ident = "HP Compaq nc6000",
  1347. .matches = {
  1348. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1349. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nc6000"),
  1350. },
  1351. /* PCI slot number of the controller */
  1352. .driver_data = (void *)0x1FUL,
  1353. },
  1354. { } /* terminate list */
  1355. };
  1356. const struct dmi_system_id *dmi = dmi_first_match(broken_systems);
  1357. if (dmi) {
  1358. unsigned long slot = (unsigned long)dmi->driver_data;
  1359. /* apply the quirk only to on-board controllers */
  1360. return slot == PCI_SLOT(pdev->devfn);
  1361. }
  1362. return false;
  1363. }
  1364. /**
  1365. * piix_init_one - Register PIIX ATA PCI device with kernel services
  1366. * @pdev: PCI device to register
  1367. * @ent: Entry in piix_pci_tbl matching with @pdev
  1368. *
  1369. * Called from kernel PCI layer. We probe for combined mode (sigh),
  1370. * and then hand over control to libata, for it to do the rest.
  1371. *
  1372. * LOCKING:
  1373. * Inherited from PCI layer (may sleep).
  1374. *
  1375. * RETURNS:
  1376. * Zero on success, or -ERRNO value.
  1377. */
  1378. static int __devinit piix_init_one(struct pci_dev *pdev,
  1379. const struct pci_device_id *ent)
  1380. {
  1381. struct device *dev = &pdev->dev;
  1382. struct ata_port_info port_info[2];
  1383. const struct ata_port_info *ppi[] = { &port_info[0], &port_info[1] };
  1384. struct scsi_host_template *sht = &piix_sht;
  1385. unsigned long port_flags;
  1386. struct ata_host *host;
  1387. struct piix_host_priv *hpriv;
  1388. int rc;
  1389. ata_print_version_once(&pdev->dev, DRV_VERSION);
  1390. /* no hotplugging support for later devices (FIXME) */
  1391. if (!in_module_init && ent->driver_data >= ich5_sata)
  1392. return -ENODEV;
  1393. if (piix_broken_system_poweroff(pdev)) {
  1394. piix_port_info[ent->driver_data].flags |=
  1395. ATA_FLAG_NO_POWEROFF_SPINDOWN |
  1396. ATA_FLAG_NO_HIBERNATE_SPINDOWN;
  1397. dev_info(&pdev->dev, "quirky BIOS, skipping spindown "
  1398. "on poweroff and hibernation\n");
  1399. }
  1400. port_info[0] = piix_port_info[ent->driver_data];
  1401. port_info[1] = piix_port_info[ent->driver_data];
  1402. port_flags = port_info[0].flags;
  1403. /* enable device and prepare host */
  1404. rc = pcim_enable_device(pdev);
  1405. if (rc)
  1406. return rc;
  1407. hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
  1408. if (!hpriv)
  1409. return -ENOMEM;
  1410. /* Save IOCFG, this will be used for cable detection, quirk
  1411. * detection and restoration on detach. This is necessary
  1412. * because some ACPI implementations mess up cable related
  1413. * bits on _STM. Reported on kernel bz#11879.
  1414. */
  1415. pci_read_config_dword(pdev, PIIX_IOCFG, &hpriv->saved_iocfg);
  1416. /* ICH6R may be driven by either ata_piix or ahci driver
  1417. * regardless of BIOS configuration. Make sure AHCI mode is
  1418. * off.
  1419. */
  1420. if (pdev->vendor == PCI_VENDOR_ID_INTEL && pdev->device == 0x2652) {
  1421. rc = piix_disable_ahci(pdev);
  1422. if (rc)
  1423. return rc;
  1424. }
  1425. /* SATA map init can change port_info, do it before prepping host */
  1426. if (port_flags & ATA_FLAG_SATA)
  1427. hpriv->map = piix_init_sata_map(pdev, port_info,
  1428. piix_map_db_table[ent->driver_data]);
  1429. rc = ata_pci_bmdma_prepare_host(pdev, ppi, &host);
  1430. if (rc)
  1431. return rc;
  1432. host->private_data = hpriv;
  1433. /* initialize controller */
  1434. if (port_flags & ATA_FLAG_SATA) {
  1435. piix_init_pcs(host, piix_map_db_table[ent->driver_data]);
  1436. rc = piix_init_sidpr(host);
  1437. if (rc)
  1438. return rc;
  1439. if (host->ports[0]->ops == &piix_sidpr_sata_ops)
  1440. sht = &piix_sidpr_sht;
  1441. }
  1442. /* apply IOCFG bit18 quirk */
  1443. piix_iocfg_bit18_quirk(host);
  1444. /* On ICH5, some BIOSen disable the interrupt using the
  1445. * PCI_COMMAND_INTX_DISABLE bit added in PCI 2.3.
  1446. * On ICH6, this bit has the same effect, but only when
  1447. * MSI is disabled (and it is disabled, as we don't use
  1448. * message-signalled interrupts currently).
  1449. */
  1450. if (port_flags & PIIX_FLAG_CHECKINTR)
  1451. pci_intx(pdev, 1);
  1452. if (piix_check_450nx_errata(pdev)) {
  1453. /* This writes into the master table but it does not
  1454. really matter for this errata as we will apply it to
  1455. all the PIIX devices on the board */
  1456. host->ports[0]->mwdma_mask = 0;
  1457. host->ports[0]->udma_mask = 0;
  1458. host->ports[1]->mwdma_mask = 0;
  1459. host->ports[1]->udma_mask = 0;
  1460. }
  1461. host->flags |= ATA_HOST_PARALLEL_SCAN;
  1462. pci_set_master(pdev);
  1463. return ata_pci_sff_activate_host(host, ata_bmdma_interrupt, sht);
  1464. }
  1465. static void piix_remove_one(struct pci_dev *pdev)
  1466. {
  1467. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  1468. struct piix_host_priv *hpriv = host->private_data;
  1469. pci_write_config_dword(pdev, PIIX_IOCFG, hpriv->saved_iocfg);
  1470. ata_pci_remove_one(pdev);
  1471. }
  1472. static int __init piix_init(void)
  1473. {
  1474. int rc;
  1475. DPRINTK("pci_register_driver\n");
  1476. rc = pci_register_driver(&piix_pci_driver);
  1477. if (rc)
  1478. return rc;
  1479. in_module_init = 0;
  1480. DPRINTK("done\n");
  1481. return 0;
  1482. }
  1483. static void __exit piix_exit(void)
  1484. {
  1485. pci_unregister_driver(&piix_pci_driver);
  1486. }
  1487. module_init(piix_init);
  1488. module_exit(piix_exit);