ata_piix.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  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. /* SATA Controller IDE (Lynx Point) */
  307. { 0x8086, 0x8c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_snb },
  308. /* SATA Controller IDE (Lynx Point) */
  309. { 0x8086, 0x8c01, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_snb },
  310. /* SATA Controller IDE (Lynx Point) */
  311. { 0x8086, 0x8c08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  312. /* SATA Controller IDE (Lynx Point) */
  313. { 0x8086, 0x8c09, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  314. { } /* terminate list */
  315. };
  316. static struct pci_driver piix_pci_driver = {
  317. .name = DRV_NAME,
  318. .id_table = piix_pci_tbl,
  319. .probe = piix_init_one,
  320. .remove = piix_remove_one,
  321. #ifdef CONFIG_PM
  322. .suspend = piix_pci_device_suspend,
  323. .resume = piix_pci_device_resume,
  324. #endif
  325. };
  326. static struct scsi_host_template piix_sht = {
  327. ATA_BMDMA_SHT(DRV_NAME),
  328. };
  329. static struct ata_port_operations piix_sata_ops = {
  330. .inherits = &ata_bmdma32_port_ops,
  331. .sff_irq_check = piix_irq_check,
  332. .port_start = piix_port_start,
  333. };
  334. static struct ata_port_operations piix_pata_ops = {
  335. .inherits = &piix_sata_ops,
  336. .cable_detect = ata_cable_40wire,
  337. .set_piomode = piix_set_piomode,
  338. .set_dmamode = piix_set_dmamode,
  339. .prereset = piix_pata_prereset,
  340. };
  341. static struct ata_port_operations piix_vmw_ops = {
  342. .inherits = &piix_pata_ops,
  343. .bmdma_status = piix_vmw_bmdma_status,
  344. };
  345. static struct ata_port_operations ich_pata_ops = {
  346. .inherits = &piix_pata_ops,
  347. .cable_detect = ich_pata_cable_detect,
  348. .set_dmamode = ich_set_dmamode,
  349. };
  350. static struct device_attribute *piix_sidpr_shost_attrs[] = {
  351. &dev_attr_link_power_management_policy,
  352. NULL
  353. };
  354. static struct scsi_host_template piix_sidpr_sht = {
  355. ATA_BMDMA_SHT(DRV_NAME),
  356. .shost_attrs = piix_sidpr_shost_attrs,
  357. };
  358. static struct ata_port_operations piix_sidpr_sata_ops = {
  359. .inherits = &piix_sata_ops,
  360. .hardreset = sata_std_hardreset,
  361. .scr_read = piix_sidpr_scr_read,
  362. .scr_write = piix_sidpr_scr_write,
  363. .set_lpm = piix_sidpr_set_lpm,
  364. };
  365. static const struct piix_map_db ich5_map_db = {
  366. .mask = 0x7,
  367. .port_enable = 0x3,
  368. .map = {
  369. /* PM PS SM SS MAP */
  370. { P0, NA, P1, NA }, /* 000b */
  371. { P1, NA, P0, NA }, /* 001b */
  372. { RV, RV, RV, RV },
  373. { RV, RV, RV, RV },
  374. { P0, P1, IDE, IDE }, /* 100b */
  375. { P1, P0, IDE, IDE }, /* 101b */
  376. { IDE, IDE, P0, P1 }, /* 110b */
  377. { IDE, IDE, P1, P0 }, /* 111b */
  378. },
  379. };
  380. static const struct piix_map_db ich6_map_db = {
  381. .mask = 0x3,
  382. .port_enable = 0xf,
  383. .map = {
  384. /* PM PS SM SS MAP */
  385. { P0, P2, P1, P3 }, /* 00b */
  386. { IDE, IDE, P1, P3 }, /* 01b */
  387. { P0, P2, IDE, IDE }, /* 10b */
  388. { RV, RV, RV, RV },
  389. },
  390. };
  391. static const struct piix_map_db ich6m_map_db = {
  392. .mask = 0x3,
  393. .port_enable = 0x5,
  394. /* Map 01b isn't specified in the doc but some notebooks use
  395. * it anyway. MAP 01b have been spotted on both ICH6M and
  396. * ICH7M.
  397. */
  398. .map = {
  399. /* PM PS SM SS MAP */
  400. { P0, P2, NA, NA }, /* 00b */
  401. { IDE, IDE, P1, P3 }, /* 01b */
  402. { P0, P2, IDE, IDE }, /* 10b */
  403. { RV, RV, RV, RV },
  404. },
  405. };
  406. static const struct piix_map_db ich8_map_db = {
  407. .mask = 0x3,
  408. .port_enable = 0xf,
  409. .map = {
  410. /* PM PS SM SS MAP */
  411. { P0, P2, P1, P3 }, /* 00b (hardwired when in AHCI) */
  412. { RV, RV, RV, RV },
  413. { P0, P2, IDE, IDE }, /* 10b (IDE mode) */
  414. { RV, RV, RV, RV },
  415. },
  416. };
  417. static const struct piix_map_db ich8_2port_map_db = {
  418. .mask = 0x3,
  419. .port_enable = 0x3,
  420. .map = {
  421. /* PM PS SM SS MAP */
  422. { P0, NA, P1, NA }, /* 00b */
  423. { RV, RV, RV, RV }, /* 01b */
  424. { RV, RV, RV, RV }, /* 10b */
  425. { RV, RV, RV, RV },
  426. },
  427. };
  428. static const struct piix_map_db ich8m_apple_map_db = {
  429. .mask = 0x3,
  430. .port_enable = 0x1,
  431. .map = {
  432. /* PM PS SM SS MAP */
  433. { P0, NA, NA, NA }, /* 00b */
  434. { RV, RV, RV, RV },
  435. { P0, P2, IDE, IDE }, /* 10b */
  436. { RV, RV, RV, RV },
  437. },
  438. };
  439. static const struct piix_map_db tolapai_map_db = {
  440. .mask = 0x3,
  441. .port_enable = 0x3,
  442. .map = {
  443. /* PM PS SM SS MAP */
  444. { P0, NA, P1, NA }, /* 00b */
  445. { RV, RV, RV, RV }, /* 01b */
  446. { RV, RV, RV, RV }, /* 10b */
  447. { RV, RV, RV, RV },
  448. },
  449. };
  450. static const struct piix_map_db *piix_map_db_table[] = {
  451. [ich5_sata] = &ich5_map_db,
  452. [ich6_sata] = &ich6_map_db,
  453. [ich6m_sata] = &ich6m_map_db,
  454. [ich8_sata] = &ich8_map_db,
  455. [ich8_2port_sata] = &ich8_2port_map_db,
  456. [ich8m_apple_sata] = &ich8m_apple_map_db,
  457. [tolapai_sata] = &tolapai_map_db,
  458. [ich8_sata_snb] = &ich8_map_db,
  459. };
  460. static struct ata_port_info piix_port_info[] = {
  461. [piix_pata_mwdma] = /* PIIX3 MWDMA only */
  462. {
  463. .flags = PIIX_PATA_FLAGS,
  464. .pio_mask = ATA_PIO4,
  465. .mwdma_mask = ATA_MWDMA12_ONLY, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
  466. .port_ops = &piix_pata_ops,
  467. },
  468. [piix_pata_33] = /* PIIX4 at 33MHz */
  469. {
  470. .flags = PIIX_PATA_FLAGS,
  471. .pio_mask = ATA_PIO4,
  472. .mwdma_mask = ATA_MWDMA12_ONLY, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
  473. .udma_mask = ATA_UDMA2,
  474. .port_ops = &piix_pata_ops,
  475. },
  476. [ich_pata_33] = /* ICH0 - ICH at 33Mhz*/
  477. {
  478. .flags = PIIX_PATA_FLAGS,
  479. .pio_mask = ATA_PIO4,
  480. .mwdma_mask = ATA_MWDMA12_ONLY, /* Check: maybe MWDMA0 is ok */
  481. .udma_mask = ATA_UDMA2,
  482. .port_ops = &ich_pata_ops,
  483. },
  484. [ich_pata_66] = /* ICH controllers up to 66MHz */
  485. {
  486. .flags = PIIX_PATA_FLAGS,
  487. .pio_mask = ATA_PIO4,
  488. .mwdma_mask = ATA_MWDMA12_ONLY, /* MWDMA0 is broken on chip */
  489. .udma_mask = ATA_UDMA4,
  490. .port_ops = &ich_pata_ops,
  491. },
  492. [ich_pata_100] =
  493. {
  494. .flags = PIIX_PATA_FLAGS | PIIX_FLAG_CHECKINTR,
  495. .pio_mask = ATA_PIO4,
  496. .mwdma_mask = ATA_MWDMA12_ONLY,
  497. .udma_mask = ATA_UDMA5,
  498. .port_ops = &ich_pata_ops,
  499. },
  500. [ich_pata_100_nomwdma1] =
  501. {
  502. .flags = PIIX_PATA_FLAGS | PIIX_FLAG_CHECKINTR,
  503. .pio_mask = ATA_PIO4,
  504. .mwdma_mask = ATA_MWDMA2_ONLY,
  505. .udma_mask = ATA_UDMA5,
  506. .port_ops = &ich_pata_ops,
  507. },
  508. [ich5_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. [ich6_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. [ich6m_sata] =
  525. {
  526. .flags = PIIX_SATA_FLAGS,
  527. .pio_mask = ATA_PIO4,
  528. .mwdma_mask = ATA_MWDMA2,
  529. .udma_mask = ATA_UDMA6,
  530. .port_ops = &piix_sata_ops,
  531. },
  532. [ich8_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. [ich8_2port_sata] =
  541. {
  542. .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SIDPR,
  543. .pio_mask = ATA_PIO4,
  544. .mwdma_mask = ATA_MWDMA2,
  545. .udma_mask = ATA_UDMA6,
  546. .port_ops = &piix_sata_ops,
  547. },
  548. [tolapai_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. [ich8m_apple_sata] =
  557. {
  558. .flags = PIIX_SATA_FLAGS,
  559. .pio_mask = ATA_PIO4,
  560. .mwdma_mask = ATA_MWDMA2,
  561. .udma_mask = ATA_UDMA6,
  562. .port_ops = &piix_sata_ops,
  563. },
  564. [piix_pata_vmw] =
  565. {
  566. .flags = PIIX_PATA_FLAGS,
  567. .pio_mask = ATA_PIO4,
  568. .mwdma_mask = ATA_MWDMA12_ONLY, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
  569. .udma_mask = ATA_UDMA2,
  570. .port_ops = &piix_vmw_ops,
  571. },
  572. /*
  573. * some Sandybridge chipsets have broken 32 mode up to now,
  574. * see https://bugzilla.kernel.org/show_bug.cgi?id=40592
  575. */
  576. [ich8_sata_snb] =
  577. {
  578. .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SIDPR | PIIX_FLAG_PIO16,
  579. .pio_mask = ATA_PIO4,
  580. .mwdma_mask = ATA_MWDMA2,
  581. .udma_mask = ATA_UDMA6,
  582. .port_ops = &piix_sata_ops,
  583. },
  584. };
  585. static struct pci_bits piix_enable_bits[] = {
  586. { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
  587. { 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */
  588. };
  589. MODULE_AUTHOR("Andre Hedrick, Alan Cox, Andrzej Krzysztofowicz, Jeff Garzik");
  590. MODULE_DESCRIPTION("SCSI low-level driver for Intel PIIX/ICH ATA controllers");
  591. MODULE_LICENSE("GPL");
  592. MODULE_DEVICE_TABLE(pci, piix_pci_tbl);
  593. MODULE_VERSION(DRV_VERSION);
  594. struct ich_laptop {
  595. u16 device;
  596. u16 subvendor;
  597. u16 subdevice;
  598. };
  599. /*
  600. * List of laptops that use short cables rather than 80 wire
  601. */
  602. static const struct ich_laptop ich_laptop[] = {
  603. /* devid, subvendor, subdev */
  604. { 0x27DF, 0x0005, 0x0280 }, /* ICH7 on Acer 5602WLMi */
  605. { 0x27DF, 0x1025, 0x0102 }, /* ICH7 on Acer 5602aWLMi */
  606. { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */
  607. { 0x27DF, 0x1028, 0x02b0 }, /* ICH7 on unknown Dell */
  608. { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */
  609. { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */
  610. { 0x27DF, 0x103C, 0x361a }, /* ICH7 on unknown HP */
  611. { 0x27DF, 0x1071, 0xD221 }, /* ICH7 on Hercules EC-900 */
  612. { 0x27DF, 0x152D, 0x0778 }, /* ICH7 on unknown Intel */
  613. { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on ACER Aspire 2023WLMi */
  614. { 0x24CA, 0x1025, 0x003d }, /* ICH4 on ACER TM290 */
  615. { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */
  616. { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
  617. { 0x27df, 0x104d, 0x900e }, /* ICH7 on Sony TZ-90 */
  618. /* end marker */
  619. { 0, }
  620. };
  621. static int piix_port_start(struct ata_port *ap)
  622. {
  623. if (!(ap->flags & PIIX_FLAG_PIO16))
  624. ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE;
  625. return ata_bmdma_port_start(ap);
  626. }
  627. /**
  628. * ich_pata_cable_detect - Probe host controller cable detect info
  629. * @ap: Port for which cable detect info is desired
  630. *
  631. * Read 80c cable indicator from ATA PCI device's PCI config
  632. * register. This register is normally set by firmware (BIOS).
  633. *
  634. * LOCKING:
  635. * None (inherited from caller).
  636. */
  637. static int ich_pata_cable_detect(struct ata_port *ap)
  638. {
  639. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  640. struct piix_host_priv *hpriv = ap->host->private_data;
  641. const struct ich_laptop *lap = &ich_laptop[0];
  642. u8 mask;
  643. /* Check for specials - Acer Aspire 5602WLMi */
  644. while (lap->device) {
  645. if (lap->device == pdev->device &&
  646. lap->subvendor == pdev->subsystem_vendor &&
  647. lap->subdevice == pdev->subsystem_device)
  648. return ATA_CBL_PATA40_SHORT;
  649. lap++;
  650. }
  651. /* check BIOS cable detect results */
  652. mask = ap->port_no == 0 ? PIIX_80C_PRI : PIIX_80C_SEC;
  653. if ((hpriv->saved_iocfg & mask) == 0)
  654. return ATA_CBL_PATA40;
  655. return ATA_CBL_PATA80;
  656. }
  657. /**
  658. * piix_pata_prereset - prereset for PATA host controller
  659. * @link: Target link
  660. * @deadline: deadline jiffies for the operation
  661. *
  662. * LOCKING:
  663. * None (inherited from caller).
  664. */
  665. static int piix_pata_prereset(struct ata_link *link, unsigned long deadline)
  666. {
  667. struct ata_port *ap = link->ap;
  668. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  669. if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no]))
  670. return -ENOENT;
  671. return ata_sff_prereset(link, deadline);
  672. }
  673. static DEFINE_SPINLOCK(piix_lock);
  674. static void piix_set_timings(struct ata_port *ap, struct ata_device *adev,
  675. u8 pio)
  676. {
  677. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  678. unsigned long flags;
  679. unsigned int is_slave = (adev->devno != 0);
  680. unsigned int master_port= ap->port_no ? 0x42 : 0x40;
  681. unsigned int slave_port = 0x44;
  682. u16 master_data;
  683. u8 slave_data;
  684. u8 udma_enable;
  685. int control = 0;
  686. /*
  687. * See Intel Document 298600-004 for the timing programing rules
  688. * for ICH controllers.
  689. */
  690. static const /* ISP RTC */
  691. u8 timings[][2] = { { 0, 0 },
  692. { 0, 0 },
  693. { 1, 0 },
  694. { 2, 1 },
  695. { 2, 3 }, };
  696. if (pio >= 2)
  697. control |= 1; /* TIME1 enable */
  698. if (ata_pio_need_iordy(adev))
  699. control |= 2; /* IE enable */
  700. /* Intel specifies that the PPE functionality is for disk only */
  701. if (adev->class == ATA_DEV_ATA)
  702. control |= 4; /* PPE enable */
  703. /*
  704. * If the drive MWDMA is faster than it can do PIO then
  705. * we must force PIO into PIO0
  706. */
  707. if (adev->pio_mode < XFER_PIO_0 + pio)
  708. /* Enable DMA timing only */
  709. control |= 8; /* PIO cycles in PIO0 */
  710. spin_lock_irqsave(&piix_lock, flags);
  711. /* PIO configuration clears DTE unconditionally. It will be
  712. * programmed in set_dmamode which is guaranteed to be called
  713. * after set_piomode if any DMA mode is available.
  714. */
  715. pci_read_config_word(dev, master_port, &master_data);
  716. if (is_slave) {
  717. /* clear TIME1|IE1|PPE1|DTE1 */
  718. master_data &= 0xff0f;
  719. /* enable PPE1, IE1 and TIME1 as needed */
  720. master_data |= (control << 4);
  721. pci_read_config_byte(dev, slave_port, &slave_data);
  722. slave_data &= (ap->port_no ? 0x0f : 0xf0);
  723. /* Load the timing nibble for this slave */
  724. slave_data |= ((timings[pio][0] << 2) | timings[pio][1])
  725. << (ap->port_no ? 4 : 0);
  726. } else {
  727. /* clear ISP|RCT|TIME0|IE0|PPE0|DTE0 */
  728. master_data &= 0xccf0;
  729. /* Enable PPE, IE and TIME as appropriate */
  730. master_data |= control;
  731. /* load ISP and RCT */
  732. master_data |=
  733. (timings[pio][0] << 12) |
  734. (timings[pio][1] << 8);
  735. }
  736. /* Enable SITRE (separate slave timing register) */
  737. master_data |= 0x4000;
  738. pci_write_config_word(dev, master_port, master_data);
  739. if (is_slave)
  740. pci_write_config_byte(dev, slave_port, slave_data);
  741. /* Ensure the UDMA bit is off - it will be turned back on if
  742. UDMA is selected */
  743. if (ap->udma_mask) {
  744. pci_read_config_byte(dev, 0x48, &udma_enable);
  745. udma_enable &= ~(1 << (2 * ap->port_no + adev->devno));
  746. pci_write_config_byte(dev, 0x48, udma_enable);
  747. }
  748. spin_unlock_irqrestore(&piix_lock, flags);
  749. }
  750. /**
  751. * piix_set_piomode - Initialize host controller PATA PIO timings
  752. * @ap: Port whose timings we are configuring
  753. * @adev: Drive in question
  754. *
  755. * Set PIO mode for device, in host controller PCI config space.
  756. *
  757. * LOCKING:
  758. * None (inherited from caller).
  759. */
  760. static void piix_set_piomode(struct ata_port *ap, struct ata_device *adev)
  761. {
  762. piix_set_timings(ap, adev, adev->pio_mode - XFER_PIO_0);
  763. }
  764. /**
  765. * do_pata_set_dmamode - Initialize host controller PATA PIO timings
  766. * @ap: Port whose timings we are configuring
  767. * @adev: Drive in question
  768. * @isich: set if the chip is an ICH device
  769. *
  770. * Set UDMA mode for device, in host controller PCI config space.
  771. *
  772. * LOCKING:
  773. * None (inherited from caller).
  774. */
  775. static void do_pata_set_dmamode(struct ata_port *ap, struct ata_device *adev, int isich)
  776. {
  777. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  778. unsigned long flags;
  779. u8 speed = adev->dma_mode;
  780. int devid = adev->devno + 2 * ap->port_no;
  781. u8 udma_enable = 0;
  782. if (speed >= XFER_UDMA_0) {
  783. unsigned int udma = speed - XFER_UDMA_0;
  784. u16 udma_timing;
  785. u16 ideconf;
  786. int u_clock, u_speed;
  787. spin_lock_irqsave(&piix_lock, flags);
  788. pci_read_config_byte(dev, 0x48, &udma_enable);
  789. /*
  790. * UDMA is handled by a combination of clock switching and
  791. * selection of dividers
  792. *
  793. * Handy rule: Odd modes are UDMATIMx 01, even are 02
  794. * except UDMA0 which is 00
  795. */
  796. u_speed = min(2 - (udma & 1), udma);
  797. if (udma == 5)
  798. u_clock = 0x1000; /* 100Mhz */
  799. else if (udma > 2)
  800. u_clock = 1; /* 66Mhz */
  801. else
  802. u_clock = 0; /* 33Mhz */
  803. udma_enable |= (1 << devid);
  804. /* Load the CT/RP selection */
  805. pci_read_config_word(dev, 0x4A, &udma_timing);
  806. udma_timing &= ~(3 << (4 * devid));
  807. udma_timing |= u_speed << (4 * devid);
  808. pci_write_config_word(dev, 0x4A, udma_timing);
  809. if (isich) {
  810. /* Select a 33/66/100Mhz clock */
  811. pci_read_config_word(dev, 0x54, &ideconf);
  812. ideconf &= ~(0x1001 << devid);
  813. ideconf |= u_clock << devid;
  814. /* For ICH or later we should set bit 10 for better
  815. performance (WR_PingPong_En) */
  816. pci_write_config_word(dev, 0x54, ideconf);
  817. }
  818. pci_write_config_byte(dev, 0x48, udma_enable);
  819. spin_unlock_irqrestore(&piix_lock, flags);
  820. } else {
  821. /* MWDMA is driven by the PIO timings. */
  822. unsigned int mwdma = speed - XFER_MW_DMA_0;
  823. const unsigned int needed_pio[3] = {
  824. XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
  825. };
  826. int pio = needed_pio[mwdma] - XFER_PIO_0;
  827. /* XFER_PIO_0 is never used currently */
  828. piix_set_timings(ap, adev, pio);
  829. }
  830. }
  831. /**
  832. * piix_set_dmamode - Initialize host controller PATA DMA timings
  833. * @ap: Port whose timings we are configuring
  834. * @adev: um
  835. *
  836. * Set MW/UDMA mode for device, in host controller PCI config space.
  837. *
  838. * LOCKING:
  839. * None (inherited from caller).
  840. */
  841. static void piix_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  842. {
  843. do_pata_set_dmamode(ap, adev, 0);
  844. }
  845. /**
  846. * ich_set_dmamode - Initialize host controller PATA DMA timings
  847. * @ap: Port whose timings we are configuring
  848. * @adev: um
  849. *
  850. * Set MW/UDMA mode for device, in host controller PCI config space.
  851. *
  852. * LOCKING:
  853. * None (inherited from caller).
  854. */
  855. static void ich_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  856. {
  857. do_pata_set_dmamode(ap, adev, 1);
  858. }
  859. /*
  860. * Serial ATA Index/Data Pair Superset Registers access
  861. *
  862. * Beginning from ICH8, there's a sane way to access SCRs using index
  863. * and data register pair located at BAR5 which means that we have
  864. * separate SCRs for master and slave. This is handled using libata
  865. * slave_link facility.
  866. */
  867. static const int piix_sidx_map[] = {
  868. [SCR_STATUS] = 0,
  869. [SCR_ERROR] = 2,
  870. [SCR_CONTROL] = 1,
  871. };
  872. static void piix_sidpr_sel(struct ata_link *link, unsigned int reg)
  873. {
  874. struct ata_port *ap = link->ap;
  875. struct piix_host_priv *hpriv = ap->host->private_data;
  876. iowrite32(((ap->port_no * 2 + link->pmp) << 8) | piix_sidx_map[reg],
  877. hpriv->sidpr + PIIX_SIDPR_IDX);
  878. }
  879. static int piix_sidpr_scr_read(struct ata_link *link,
  880. unsigned int reg, u32 *val)
  881. {
  882. struct piix_host_priv *hpriv = link->ap->host->private_data;
  883. if (reg >= ARRAY_SIZE(piix_sidx_map))
  884. return -EINVAL;
  885. piix_sidpr_sel(link, reg);
  886. *val = ioread32(hpriv->sidpr + PIIX_SIDPR_DATA);
  887. return 0;
  888. }
  889. static int piix_sidpr_scr_write(struct ata_link *link,
  890. unsigned int reg, u32 val)
  891. {
  892. struct piix_host_priv *hpriv = link->ap->host->private_data;
  893. if (reg >= ARRAY_SIZE(piix_sidx_map))
  894. return -EINVAL;
  895. piix_sidpr_sel(link, reg);
  896. iowrite32(val, hpriv->sidpr + PIIX_SIDPR_DATA);
  897. return 0;
  898. }
  899. static int piix_sidpr_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
  900. unsigned hints)
  901. {
  902. return sata_link_scr_lpm(link, policy, false);
  903. }
  904. static bool piix_irq_check(struct ata_port *ap)
  905. {
  906. if (unlikely(!ap->ioaddr.bmdma_addr))
  907. return false;
  908. return ap->ops->bmdma_status(ap) & ATA_DMA_INTR;
  909. }
  910. #ifdef CONFIG_PM
  911. static int piix_broken_suspend(void)
  912. {
  913. static const struct dmi_system_id sysids[] = {
  914. {
  915. .ident = "TECRA M3",
  916. .matches = {
  917. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  918. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M3"),
  919. },
  920. },
  921. {
  922. .ident = "TECRA M3",
  923. .matches = {
  924. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  925. DMI_MATCH(DMI_PRODUCT_NAME, "Tecra M3"),
  926. },
  927. },
  928. {
  929. .ident = "TECRA M4",
  930. .matches = {
  931. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  932. DMI_MATCH(DMI_PRODUCT_NAME, "Tecra M4"),
  933. },
  934. },
  935. {
  936. .ident = "TECRA M4",
  937. .matches = {
  938. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  939. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M4"),
  940. },
  941. },
  942. {
  943. .ident = "TECRA M5",
  944. .matches = {
  945. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  946. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M5"),
  947. },
  948. },
  949. {
  950. .ident = "TECRA M6",
  951. .matches = {
  952. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  953. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M6"),
  954. },
  955. },
  956. {
  957. .ident = "TECRA M7",
  958. .matches = {
  959. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  960. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M7"),
  961. },
  962. },
  963. {
  964. .ident = "TECRA A8",
  965. .matches = {
  966. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  967. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A8"),
  968. },
  969. },
  970. {
  971. .ident = "Satellite R20",
  972. .matches = {
  973. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  974. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite R20"),
  975. },
  976. },
  977. {
  978. .ident = "Satellite R25",
  979. .matches = {
  980. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  981. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite R25"),
  982. },
  983. },
  984. {
  985. .ident = "Satellite U200",
  986. .matches = {
  987. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  988. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite U200"),
  989. },
  990. },
  991. {
  992. .ident = "Satellite U200",
  993. .matches = {
  994. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  995. DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE U200"),
  996. },
  997. },
  998. {
  999. .ident = "Satellite Pro U200",
  1000. .matches = {
  1001. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1002. DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE PRO U200"),
  1003. },
  1004. },
  1005. {
  1006. .ident = "Satellite U205",
  1007. .matches = {
  1008. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1009. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite U205"),
  1010. },
  1011. },
  1012. {
  1013. .ident = "SATELLITE U205",
  1014. .matches = {
  1015. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1016. DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE U205"),
  1017. },
  1018. },
  1019. {
  1020. .ident = "Satellite Pro A120",
  1021. .matches = {
  1022. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1023. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite Pro A120"),
  1024. },
  1025. },
  1026. {
  1027. .ident = "Portege M500",
  1028. .matches = {
  1029. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1030. DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M500"),
  1031. },
  1032. },
  1033. {
  1034. .ident = "VGN-BX297XP",
  1035. .matches = {
  1036. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  1037. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-BX297XP"),
  1038. },
  1039. },
  1040. { } /* terminate list */
  1041. };
  1042. static const char *oemstrs[] = {
  1043. "Tecra M3,",
  1044. };
  1045. int i;
  1046. if (dmi_check_system(sysids))
  1047. return 1;
  1048. for (i = 0; i < ARRAY_SIZE(oemstrs); i++)
  1049. if (dmi_find_device(DMI_DEV_TYPE_OEM_STRING, oemstrs[i], NULL))
  1050. return 1;
  1051. /* TECRA M4 sometimes forgets its identify and reports bogus
  1052. * DMI information. As the bogus information is a bit
  1053. * generic, match as many entries as possible. This manual
  1054. * matching is necessary because dmi_system_id.matches is
  1055. * limited to four entries.
  1056. */
  1057. if (dmi_match(DMI_SYS_VENDOR, "TOSHIBA") &&
  1058. dmi_match(DMI_PRODUCT_NAME, "000000") &&
  1059. dmi_match(DMI_PRODUCT_VERSION, "000000") &&
  1060. dmi_match(DMI_PRODUCT_SERIAL, "000000") &&
  1061. dmi_match(DMI_BOARD_VENDOR, "TOSHIBA") &&
  1062. dmi_match(DMI_BOARD_NAME, "Portable PC") &&
  1063. dmi_match(DMI_BOARD_VERSION, "Version A0"))
  1064. return 1;
  1065. return 0;
  1066. }
  1067. static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
  1068. {
  1069. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  1070. unsigned long flags;
  1071. int rc = 0;
  1072. rc = ata_host_suspend(host, mesg);
  1073. if (rc)
  1074. return rc;
  1075. /* Some braindamaged ACPI suspend implementations expect the
  1076. * controller to be awake on entry; otherwise, it burns cpu
  1077. * cycles and power trying to do something to the sleeping
  1078. * beauty.
  1079. */
  1080. if (piix_broken_suspend() && (mesg.event & PM_EVENT_SLEEP)) {
  1081. pci_save_state(pdev);
  1082. /* mark its power state as "unknown", since we don't
  1083. * know if e.g. the BIOS will change its device state
  1084. * when we suspend.
  1085. */
  1086. if (pdev->current_state == PCI_D0)
  1087. pdev->current_state = PCI_UNKNOWN;
  1088. /* tell resume that it's waking up from broken suspend */
  1089. spin_lock_irqsave(&host->lock, flags);
  1090. host->flags |= PIIX_HOST_BROKEN_SUSPEND;
  1091. spin_unlock_irqrestore(&host->lock, flags);
  1092. } else
  1093. ata_pci_device_do_suspend(pdev, mesg);
  1094. return 0;
  1095. }
  1096. static int piix_pci_device_resume(struct pci_dev *pdev)
  1097. {
  1098. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  1099. unsigned long flags;
  1100. int rc;
  1101. if (host->flags & PIIX_HOST_BROKEN_SUSPEND) {
  1102. spin_lock_irqsave(&host->lock, flags);
  1103. host->flags &= ~PIIX_HOST_BROKEN_SUSPEND;
  1104. spin_unlock_irqrestore(&host->lock, flags);
  1105. pci_set_power_state(pdev, PCI_D0);
  1106. pci_restore_state(pdev);
  1107. /* PCI device wasn't disabled during suspend. Use
  1108. * pci_reenable_device() to avoid affecting the enable
  1109. * count.
  1110. */
  1111. rc = pci_reenable_device(pdev);
  1112. if (rc)
  1113. dev_err(&pdev->dev,
  1114. "failed to enable device after resume (%d)\n",
  1115. rc);
  1116. } else
  1117. rc = ata_pci_device_do_resume(pdev);
  1118. if (rc == 0)
  1119. ata_host_resume(host);
  1120. return rc;
  1121. }
  1122. #endif
  1123. static u8 piix_vmw_bmdma_status(struct ata_port *ap)
  1124. {
  1125. return ata_bmdma_status(ap) & ~ATA_DMA_ERR;
  1126. }
  1127. #define AHCI_PCI_BAR 5
  1128. #define AHCI_GLOBAL_CTL 0x04
  1129. #define AHCI_ENABLE (1 << 31)
  1130. static int piix_disable_ahci(struct pci_dev *pdev)
  1131. {
  1132. void __iomem *mmio;
  1133. u32 tmp;
  1134. int rc = 0;
  1135. /* BUG: pci_enable_device has not yet been called. This
  1136. * works because this device is usually set up by BIOS.
  1137. */
  1138. if (!pci_resource_start(pdev, AHCI_PCI_BAR) ||
  1139. !pci_resource_len(pdev, AHCI_PCI_BAR))
  1140. return 0;
  1141. mmio = pci_iomap(pdev, AHCI_PCI_BAR, 64);
  1142. if (!mmio)
  1143. return -ENOMEM;
  1144. tmp = ioread32(mmio + AHCI_GLOBAL_CTL);
  1145. if (tmp & AHCI_ENABLE) {
  1146. tmp &= ~AHCI_ENABLE;
  1147. iowrite32(tmp, mmio + AHCI_GLOBAL_CTL);
  1148. tmp = ioread32(mmio + AHCI_GLOBAL_CTL);
  1149. if (tmp & AHCI_ENABLE)
  1150. rc = -EIO;
  1151. }
  1152. pci_iounmap(pdev, mmio);
  1153. return rc;
  1154. }
  1155. /**
  1156. * piix_check_450nx_errata - Check for problem 450NX setup
  1157. * @ata_dev: the PCI device to check
  1158. *
  1159. * Check for the present of 450NX errata #19 and errata #25. If
  1160. * they are found return an error code so we can turn off DMA
  1161. */
  1162. static int __devinit piix_check_450nx_errata(struct pci_dev *ata_dev)
  1163. {
  1164. struct pci_dev *pdev = NULL;
  1165. u16 cfg;
  1166. int no_piix_dma = 0;
  1167. while ((pdev = pci_get_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, pdev)) != NULL) {
  1168. /* Look for 450NX PXB. Check for problem configurations
  1169. A PCI quirk checks bit 6 already */
  1170. pci_read_config_word(pdev, 0x41, &cfg);
  1171. /* Only on the original revision: IDE DMA can hang */
  1172. if (pdev->revision == 0x00)
  1173. no_piix_dma = 1;
  1174. /* On all revisions below 5 PXB bus lock must be disabled for IDE */
  1175. else if (cfg & (1<<14) && pdev->revision < 5)
  1176. no_piix_dma = 2;
  1177. }
  1178. if (no_piix_dma)
  1179. dev_warn(&ata_dev->dev,
  1180. "450NX errata present, disabling IDE DMA%s\n",
  1181. no_piix_dma == 2 ? " - a BIOS update may resolve this"
  1182. : "");
  1183. return no_piix_dma;
  1184. }
  1185. static void __devinit piix_init_pcs(struct ata_host *host,
  1186. const struct piix_map_db *map_db)
  1187. {
  1188. struct pci_dev *pdev = to_pci_dev(host->dev);
  1189. u16 pcs, new_pcs;
  1190. pci_read_config_word(pdev, ICH5_PCS, &pcs);
  1191. new_pcs = pcs | map_db->port_enable;
  1192. if (new_pcs != pcs) {
  1193. DPRINTK("updating PCS from 0x%x to 0x%x\n", pcs, new_pcs);
  1194. pci_write_config_word(pdev, ICH5_PCS, new_pcs);
  1195. msleep(150);
  1196. }
  1197. }
  1198. static const int *__devinit piix_init_sata_map(struct pci_dev *pdev,
  1199. struct ata_port_info *pinfo,
  1200. const struct piix_map_db *map_db)
  1201. {
  1202. const int *map;
  1203. int i, invalid_map = 0;
  1204. u8 map_value;
  1205. pci_read_config_byte(pdev, ICH5_PMR, &map_value);
  1206. map = map_db->map[map_value & map_db->mask];
  1207. dev_info(&pdev->dev, "MAP [");
  1208. for (i = 0; i < 4; i++) {
  1209. switch (map[i]) {
  1210. case RV:
  1211. invalid_map = 1;
  1212. pr_cont(" XX");
  1213. break;
  1214. case NA:
  1215. pr_cont(" --");
  1216. break;
  1217. case IDE:
  1218. WARN_ON((i & 1) || map[i + 1] != IDE);
  1219. pinfo[i / 2] = piix_port_info[ich_pata_100];
  1220. i++;
  1221. pr_cont(" IDE IDE");
  1222. break;
  1223. default:
  1224. pr_cont(" P%d", map[i]);
  1225. if (i & 1)
  1226. pinfo[i / 2].flags |= ATA_FLAG_SLAVE_POSS;
  1227. break;
  1228. }
  1229. }
  1230. pr_cont(" ]\n");
  1231. if (invalid_map)
  1232. dev_err(&pdev->dev, "invalid MAP value %u\n", map_value);
  1233. return map;
  1234. }
  1235. static bool piix_no_sidpr(struct ata_host *host)
  1236. {
  1237. struct pci_dev *pdev = to_pci_dev(host->dev);
  1238. /*
  1239. * Samsung DB-P70 only has three ATA ports exposed and
  1240. * curiously the unconnected first port reports link online
  1241. * while not responding to SRST protocol causing excessive
  1242. * detection delay.
  1243. *
  1244. * Unfortunately, the system doesn't carry enough DMI
  1245. * information to identify the machine but does have subsystem
  1246. * vendor and device set. As it's unclear whether the
  1247. * subsystem vendor/device is used only for this specific
  1248. * board, the port can't be disabled solely with the
  1249. * information; however, turning off SIDPR access works around
  1250. * the problem. Turn it off.
  1251. *
  1252. * This problem is reported in bnc#441240.
  1253. *
  1254. * https://bugzilla.novell.com/show_bug.cgi?id=441420
  1255. */
  1256. if (pdev->vendor == PCI_VENDOR_ID_INTEL && pdev->device == 0x2920 &&
  1257. pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG &&
  1258. pdev->subsystem_device == 0xb049) {
  1259. dev_warn(host->dev,
  1260. "Samsung DB-P70 detected, disabling SIDPR\n");
  1261. return true;
  1262. }
  1263. return false;
  1264. }
  1265. static int __devinit piix_init_sidpr(struct ata_host *host)
  1266. {
  1267. struct pci_dev *pdev = to_pci_dev(host->dev);
  1268. struct piix_host_priv *hpriv = host->private_data;
  1269. struct ata_link *link0 = &host->ports[0]->link;
  1270. u32 scontrol;
  1271. int i, rc;
  1272. /* check for availability */
  1273. for (i = 0; i < 4; i++)
  1274. if (hpriv->map[i] == IDE)
  1275. return 0;
  1276. /* is it blacklisted? */
  1277. if (piix_no_sidpr(host))
  1278. return 0;
  1279. if (!(host->ports[0]->flags & PIIX_FLAG_SIDPR))
  1280. return 0;
  1281. if (pci_resource_start(pdev, PIIX_SIDPR_BAR) == 0 ||
  1282. pci_resource_len(pdev, PIIX_SIDPR_BAR) != PIIX_SIDPR_LEN)
  1283. return 0;
  1284. if (pcim_iomap_regions(pdev, 1 << PIIX_SIDPR_BAR, DRV_NAME))
  1285. return 0;
  1286. hpriv->sidpr = pcim_iomap_table(pdev)[PIIX_SIDPR_BAR];
  1287. /* SCR access via SIDPR doesn't work on some configurations.
  1288. * Give it a test drive by inhibiting power save modes which
  1289. * we'll do anyway.
  1290. */
  1291. piix_sidpr_scr_read(link0, SCR_CONTROL, &scontrol);
  1292. /* if IPM is already 3, SCR access is probably working. Don't
  1293. * un-inhibit power save modes as BIOS might have inhibited
  1294. * them for a reason.
  1295. */
  1296. if ((scontrol & 0xf00) != 0x300) {
  1297. scontrol |= 0x300;
  1298. piix_sidpr_scr_write(link0, SCR_CONTROL, scontrol);
  1299. piix_sidpr_scr_read(link0, SCR_CONTROL, &scontrol);
  1300. if ((scontrol & 0xf00) != 0x300) {
  1301. dev_info(host->dev,
  1302. "SCR access via SIDPR is available but doesn't work\n");
  1303. return 0;
  1304. }
  1305. }
  1306. /* okay, SCRs available, set ops and ask libata for slave_link */
  1307. for (i = 0; i < 2; i++) {
  1308. struct ata_port *ap = host->ports[i];
  1309. ap->ops = &piix_sidpr_sata_ops;
  1310. if (ap->flags & ATA_FLAG_SLAVE_POSS) {
  1311. rc = ata_slave_link_init(ap);
  1312. if (rc)
  1313. return rc;
  1314. }
  1315. }
  1316. return 0;
  1317. }
  1318. static void piix_iocfg_bit18_quirk(struct ata_host *host)
  1319. {
  1320. static const struct dmi_system_id sysids[] = {
  1321. {
  1322. /* Clevo M570U sets IOCFG bit 18 if the cdrom
  1323. * isn't used to boot the system which
  1324. * disables the channel.
  1325. */
  1326. .ident = "M570U",
  1327. .matches = {
  1328. DMI_MATCH(DMI_SYS_VENDOR, "Clevo Co."),
  1329. DMI_MATCH(DMI_PRODUCT_NAME, "M570U"),
  1330. },
  1331. },
  1332. { } /* terminate list */
  1333. };
  1334. struct pci_dev *pdev = to_pci_dev(host->dev);
  1335. struct piix_host_priv *hpriv = host->private_data;
  1336. if (!dmi_check_system(sysids))
  1337. return;
  1338. /* The datasheet says that bit 18 is NOOP but certain systems
  1339. * seem to use it to disable a channel. Clear the bit on the
  1340. * affected systems.
  1341. */
  1342. if (hpriv->saved_iocfg & (1 << 18)) {
  1343. dev_info(&pdev->dev, "applying IOCFG bit18 quirk\n");
  1344. pci_write_config_dword(pdev, PIIX_IOCFG,
  1345. hpriv->saved_iocfg & ~(1 << 18));
  1346. }
  1347. }
  1348. static bool piix_broken_system_poweroff(struct pci_dev *pdev)
  1349. {
  1350. static const struct dmi_system_id broken_systems[] = {
  1351. {
  1352. .ident = "HP Compaq 2510p",
  1353. .matches = {
  1354. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1355. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 2510p"),
  1356. },
  1357. /* PCI slot number of the controller */
  1358. .driver_data = (void *)0x1FUL,
  1359. },
  1360. {
  1361. .ident = "HP Compaq nc6000",
  1362. .matches = {
  1363. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1364. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nc6000"),
  1365. },
  1366. /* PCI slot number of the controller */
  1367. .driver_data = (void *)0x1FUL,
  1368. },
  1369. { } /* terminate list */
  1370. };
  1371. const struct dmi_system_id *dmi = dmi_first_match(broken_systems);
  1372. if (dmi) {
  1373. unsigned long slot = (unsigned long)dmi->driver_data;
  1374. /* apply the quirk only to on-board controllers */
  1375. return slot == PCI_SLOT(pdev->devfn);
  1376. }
  1377. return false;
  1378. }
  1379. /**
  1380. * piix_init_one - Register PIIX ATA PCI device with kernel services
  1381. * @pdev: PCI device to register
  1382. * @ent: Entry in piix_pci_tbl matching with @pdev
  1383. *
  1384. * Called from kernel PCI layer. We probe for combined mode (sigh),
  1385. * and then hand over control to libata, for it to do the rest.
  1386. *
  1387. * LOCKING:
  1388. * Inherited from PCI layer (may sleep).
  1389. *
  1390. * RETURNS:
  1391. * Zero on success, or -ERRNO value.
  1392. */
  1393. static int __devinit piix_init_one(struct pci_dev *pdev,
  1394. const struct pci_device_id *ent)
  1395. {
  1396. struct device *dev = &pdev->dev;
  1397. struct ata_port_info port_info[2];
  1398. const struct ata_port_info *ppi[] = { &port_info[0], &port_info[1] };
  1399. struct scsi_host_template *sht = &piix_sht;
  1400. unsigned long port_flags;
  1401. struct ata_host *host;
  1402. struct piix_host_priv *hpriv;
  1403. int rc;
  1404. ata_print_version_once(&pdev->dev, DRV_VERSION);
  1405. /* no hotplugging support for later devices (FIXME) */
  1406. if (!in_module_init && ent->driver_data >= ich5_sata)
  1407. return -ENODEV;
  1408. if (piix_broken_system_poweroff(pdev)) {
  1409. piix_port_info[ent->driver_data].flags |=
  1410. ATA_FLAG_NO_POWEROFF_SPINDOWN |
  1411. ATA_FLAG_NO_HIBERNATE_SPINDOWN;
  1412. dev_info(&pdev->dev, "quirky BIOS, skipping spindown "
  1413. "on poweroff and hibernation\n");
  1414. }
  1415. port_info[0] = piix_port_info[ent->driver_data];
  1416. port_info[1] = piix_port_info[ent->driver_data];
  1417. port_flags = port_info[0].flags;
  1418. /* enable device and prepare host */
  1419. rc = pcim_enable_device(pdev);
  1420. if (rc)
  1421. return rc;
  1422. hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
  1423. if (!hpriv)
  1424. return -ENOMEM;
  1425. /* Save IOCFG, this will be used for cable detection, quirk
  1426. * detection and restoration on detach. This is necessary
  1427. * because some ACPI implementations mess up cable related
  1428. * bits on _STM. Reported on kernel bz#11879.
  1429. */
  1430. pci_read_config_dword(pdev, PIIX_IOCFG, &hpriv->saved_iocfg);
  1431. /* ICH6R may be driven by either ata_piix or ahci driver
  1432. * regardless of BIOS configuration. Make sure AHCI mode is
  1433. * off.
  1434. */
  1435. if (pdev->vendor == PCI_VENDOR_ID_INTEL && pdev->device == 0x2652) {
  1436. rc = piix_disable_ahci(pdev);
  1437. if (rc)
  1438. return rc;
  1439. }
  1440. /* SATA map init can change port_info, do it before prepping host */
  1441. if (port_flags & ATA_FLAG_SATA)
  1442. hpriv->map = piix_init_sata_map(pdev, port_info,
  1443. piix_map_db_table[ent->driver_data]);
  1444. rc = ata_pci_bmdma_prepare_host(pdev, ppi, &host);
  1445. if (rc)
  1446. return rc;
  1447. host->private_data = hpriv;
  1448. /* initialize controller */
  1449. if (port_flags & ATA_FLAG_SATA) {
  1450. piix_init_pcs(host, piix_map_db_table[ent->driver_data]);
  1451. rc = piix_init_sidpr(host);
  1452. if (rc)
  1453. return rc;
  1454. if (host->ports[0]->ops == &piix_sidpr_sata_ops)
  1455. sht = &piix_sidpr_sht;
  1456. }
  1457. /* apply IOCFG bit18 quirk */
  1458. piix_iocfg_bit18_quirk(host);
  1459. /* On ICH5, some BIOSen disable the interrupt using the
  1460. * PCI_COMMAND_INTX_DISABLE bit added in PCI 2.3.
  1461. * On ICH6, this bit has the same effect, but only when
  1462. * MSI is disabled (and it is disabled, as we don't use
  1463. * message-signalled interrupts currently).
  1464. */
  1465. if (port_flags & PIIX_FLAG_CHECKINTR)
  1466. pci_intx(pdev, 1);
  1467. if (piix_check_450nx_errata(pdev)) {
  1468. /* This writes into the master table but it does not
  1469. really matter for this errata as we will apply it to
  1470. all the PIIX devices on the board */
  1471. host->ports[0]->mwdma_mask = 0;
  1472. host->ports[0]->udma_mask = 0;
  1473. host->ports[1]->mwdma_mask = 0;
  1474. host->ports[1]->udma_mask = 0;
  1475. }
  1476. host->flags |= ATA_HOST_PARALLEL_SCAN;
  1477. pci_set_master(pdev);
  1478. return ata_pci_sff_activate_host(host, ata_bmdma_interrupt, sht);
  1479. }
  1480. static void piix_remove_one(struct pci_dev *pdev)
  1481. {
  1482. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  1483. struct piix_host_priv *hpriv = host->private_data;
  1484. pci_write_config_dword(pdev, PIIX_IOCFG, hpriv->saved_iocfg);
  1485. ata_pci_remove_one(pdev);
  1486. }
  1487. static int __init piix_init(void)
  1488. {
  1489. int rc;
  1490. DPRINTK("pci_register_driver\n");
  1491. rc = pci_register_driver(&piix_pci_driver);
  1492. if (rc)
  1493. return rc;
  1494. in_module_init = 0;
  1495. DPRINTK("done\n");
  1496. return 0;
  1497. }
  1498. static void __exit piix_exit(void)
  1499. {
  1500. pci_unregister_driver(&piix_pci_driver);
  1501. }
  1502. module_init(piix_init);
  1503. module_exit(piix_exit);