ata_piix.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  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 <alan@redhat.com>
  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. * Publically available from Intel web site. Errata documentation
  42. * is also publically 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 orginal Triton
  47. * series chipsets do _not_ support independant 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 independant 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. *
  76. * Should have been BIOS fixed:
  77. * 450NX: errata #19 - DMA hangs on old 450NX
  78. * 450NX: errata #20 - DMA hangs on old 450NX
  79. * 450NX: errata #25 - Corruption with DMA on old 450NX
  80. * ICH3 errata #15 - IDE deadlock under high load
  81. * (BIOS must set dev 31 fn 0 bit 23)
  82. * ICH3 errata #18 - Don't use native mode
  83. */
  84. #include <linux/kernel.h>
  85. #include <linux/module.h>
  86. #include <linux/pci.h>
  87. #include <linux/init.h>
  88. #include <linux/blkdev.h>
  89. #include <linux/delay.h>
  90. #include <linux/device.h>
  91. #include <scsi/scsi_host.h>
  92. #include <linux/libata.h>
  93. #include <linux/dmi.h>
  94. #define DRV_NAME "ata_piix"
  95. #define DRV_VERSION "2.12"
  96. enum {
  97. PIIX_IOCFG = 0x54, /* IDE I/O configuration register */
  98. ICH5_PMR = 0x90, /* port mapping register */
  99. ICH5_PCS = 0x92, /* port control and status */
  100. PIIX_SCC = 0x0A, /* sub-class code register */
  101. PIIX_SIDPR_BAR = 5,
  102. PIIX_SIDPR_LEN = 16,
  103. PIIX_SIDPR_IDX = 0,
  104. PIIX_SIDPR_DATA = 4,
  105. PIIX_FLAG_AHCI = (1 << 27), /* AHCI possible */
  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_80C_PRI = (1 << 5) | (1 << 4),
  111. PIIX_80C_SEC = (1 << 7) | (1 << 6),
  112. /* constants for mapping table */
  113. P0 = 0, /* port 0 */
  114. P1 = 1, /* port 1 */
  115. P2 = 2, /* port 2 */
  116. P3 = 3, /* port 3 */
  117. IDE = -1, /* IDE */
  118. NA = -2, /* not avaliable */
  119. RV = -3, /* reserved */
  120. PIIX_AHCI_DEVICE = 6,
  121. /* host->flags bits */
  122. PIIX_HOST_BROKEN_SUSPEND = (1 << 24),
  123. };
  124. enum piix_controller_ids {
  125. /* controller IDs */
  126. piix_pata_mwdma, /* PIIX3 MWDMA only */
  127. piix_pata_33, /* PIIX4 at 33Mhz */
  128. ich_pata_33, /* ICH up to UDMA 33 only */
  129. ich_pata_66, /* ICH up to 66 Mhz */
  130. ich_pata_100, /* ICH up to UDMA 100 */
  131. ich5_sata,
  132. ich6_sata,
  133. ich6_sata_ahci,
  134. ich6m_sata_ahci,
  135. ich8_sata_ahci,
  136. ich8_2port_sata,
  137. ich8m_apple_sata_ahci, /* locks up on second port enable */
  138. tolapai_sata_ahci,
  139. piix_pata_vmw, /* PIIX4 for VMware, spurious DMA_ERR */
  140. };
  141. struct piix_map_db {
  142. const u32 mask;
  143. const u16 port_enable;
  144. const int map[][4];
  145. };
  146. struct piix_host_priv {
  147. const int *map;
  148. void __iomem *sidpr;
  149. };
  150. static int piix_init_one(struct pci_dev *pdev,
  151. const struct pci_device_id *ent);
  152. static void piix_pata_error_handler(struct ata_port *ap);
  153. static void piix_set_piomode(struct ata_port *ap, struct ata_device *adev);
  154. static void piix_set_dmamode(struct ata_port *ap, struct ata_device *adev);
  155. static void ich_set_dmamode(struct ata_port *ap, struct ata_device *adev);
  156. static int ich_pata_cable_detect(struct ata_port *ap);
  157. static u8 piix_vmw_bmdma_status(struct ata_port *ap);
  158. static int piix_sidpr_scr_read(struct ata_port *ap, unsigned int reg, u32 *val);
  159. static int piix_sidpr_scr_write(struct ata_port *ap, unsigned int reg, u32 val);
  160. static void piix_sidpr_error_handler(struct ata_port *ap);
  161. #ifdef CONFIG_PM
  162. static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
  163. static int piix_pci_device_resume(struct pci_dev *pdev);
  164. #endif
  165. static unsigned int in_module_init = 1;
  166. static const struct pci_device_id piix_pci_tbl[] = {
  167. /* Intel PIIX3 for the 430HX etc */
  168. { 0x8086, 0x7010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_mwdma },
  169. /* VMware ICH4 */
  170. { 0x8086, 0x7111, 0x15ad, 0x1976, 0, 0, piix_pata_vmw },
  171. /* Intel PIIX4 for the 430TX/440BX/MX chipset: UDMA 33 */
  172. /* Also PIIX4E (fn3 rev 2) and PIIX4M (fn3 rev 3) */
  173. { 0x8086, 0x7111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
  174. /* Intel PIIX4 */
  175. { 0x8086, 0x7199, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
  176. /* Intel PIIX4 */
  177. { 0x8086, 0x7601, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
  178. /* Intel PIIX */
  179. { 0x8086, 0x84CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
  180. /* Intel ICH (i810, i815, i840) UDMA 66*/
  181. { 0x8086, 0x2411, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_66 },
  182. /* Intel ICH0 : UDMA 33*/
  183. { 0x8086, 0x2421, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_33 },
  184. /* Intel ICH2M */
  185. { 0x8086, 0x244A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  186. /* Intel ICH2 (i810E2, i845, 850, 860) UDMA 100 */
  187. { 0x8086, 0x244B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  188. /* Intel ICH3M */
  189. { 0x8086, 0x248A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  190. /* Intel ICH3 (E7500/1) UDMA 100 */
  191. { 0x8086, 0x248B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  192. /* Intel ICH4 (i845GV, i845E, i852, i855) UDMA 100 */
  193. { 0x8086, 0x24CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  194. { 0x8086, 0x24CB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  195. /* Intel ICH5 */
  196. { 0x8086, 0x24DB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  197. /* C-ICH (i810E2) */
  198. { 0x8086, 0x245B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  199. /* ESB (855GME/875P + 6300ESB) UDMA 100 */
  200. { 0x8086, 0x25A2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  201. /* ICH6 (and 6) (i915) UDMA 100 */
  202. { 0x8086, 0x266F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  203. /* ICH7/7-R (i945, i975) UDMA 100*/
  204. { 0x8086, 0x27DF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  205. { 0x8086, 0x269E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  206. /* ICH8 Mobile PATA Controller */
  207. { 0x8086, 0x2850, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
  208. /* NOTE: The following PCI ids must be kept in sync with the
  209. * list in drivers/pci/quirks.c.
  210. */
  211. /* 82801EB (ICH5) */
  212. { 0x8086, 0x24d1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  213. /* 82801EB (ICH5) */
  214. { 0x8086, 0x24df, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  215. /* 6300ESB (ICH5 variant with broken PCS present bits) */
  216. { 0x8086, 0x25a3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  217. /* 6300ESB pretending RAID */
  218. { 0x8086, 0x25b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  219. /* 82801FB/FW (ICH6/ICH6W) */
  220. { 0x8086, 0x2651, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata },
  221. /* 82801FR/FRW (ICH6R/ICH6RW) */
  222. { 0x8086, 0x2652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
  223. /* 82801FBM ICH6M (ICH6R with only port 0 and 2 implemented) */
  224. { 0x8086, 0x2653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6m_sata_ahci },
  225. /* 82801GB/GR/GH (ICH7, identical to ICH6) */
  226. { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
  227. /* 2801GBM/GHM (ICH7M, identical to ICH6M) */
  228. { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6m_sata_ahci },
  229. /* Enterprise Southbridge 2 (631xESB/632xESB) */
  230. { 0x8086, 0x2680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
  231. /* SATA Controller 1 IDE (ICH8) */
  232. { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
  233. /* SATA Controller 2 IDE (ICH8) */
  234. { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  235. /* Mobile SATA Controller IDE (ICH8M) */
  236. { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
  237. /* Mobile SATA Controller IDE (ICH8M), Apple */
  238. { 0x8086, 0x2828, 0x106b, 0x00a0, 0, 0, ich8m_apple_sata_ahci },
  239. /* SATA Controller IDE (ICH9) */
  240. { 0x8086, 0x2920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
  241. /* SATA Controller IDE (ICH9) */
  242. { 0x8086, 0x2921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  243. /* SATA Controller IDE (ICH9) */
  244. { 0x8086, 0x2926, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  245. /* SATA Controller IDE (ICH9M) */
  246. { 0x8086, 0x2928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  247. /* SATA Controller IDE (ICH9M) */
  248. { 0x8086, 0x292d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  249. /* SATA Controller IDE (ICH9M) */
  250. { 0x8086, 0x292e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
  251. /* SATA Controller IDE (Tolapai) */
  252. { 0x8086, 0x5028, PCI_ANY_ID, PCI_ANY_ID, 0, 0, tolapai_sata_ahci },
  253. /* SATA Controller IDE (ICH10) */
  254. { 0x8086, 0x3a00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
  255. /* SATA Controller IDE (ICH10) */
  256. { 0x8086, 0x3a06, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  257. /* SATA Controller IDE (ICH10) */
  258. { 0x8086, 0x3a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
  259. /* SATA Controller IDE (ICH10) */
  260. { 0x8086, 0x3a26, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
  261. { } /* terminate list */
  262. };
  263. static struct pci_driver piix_pci_driver = {
  264. .name = DRV_NAME,
  265. .id_table = piix_pci_tbl,
  266. .probe = piix_init_one,
  267. .remove = ata_pci_remove_one,
  268. #ifdef CONFIG_PM
  269. .suspend = piix_pci_device_suspend,
  270. .resume = piix_pci_device_resume,
  271. #endif
  272. };
  273. static struct scsi_host_template piix_sht = {
  274. .module = THIS_MODULE,
  275. .name = DRV_NAME,
  276. .ioctl = ata_scsi_ioctl,
  277. .queuecommand = ata_scsi_queuecmd,
  278. .can_queue = ATA_DEF_QUEUE,
  279. .this_id = ATA_SHT_THIS_ID,
  280. .sg_tablesize = LIBATA_MAX_PRD,
  281. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  282. .emulated = ATA_SHT_EMULATED,
  283. .use_clustering = ATA_SHT_USE_CLUSTERING,
  284. .proc_name = DRV_NAME,
  285. .dma_boundary = ATA_DMA_BOUNDARY,
  286. .slave_configure = ata_scsi_slave_config,
  287. .slave_destroy = ata_scsi_slave_destroy,
  288. .bios_param = ata_std_bios_param,
  289. };
  290. static const struct ata_port_operations piix_pata_ops = {
  291. .set_piomode = piix_set_piomode,
  292. .set_dmamode = piix_set_dmamode,
  293. .mode_filter = ata_pci_default_filter,
  294. .tf_load = ata_tf_load,
  295. .tf_read = ata_tf_read,
  296. .check_status = ata_check_status,
  297. .exec_command = ata_exec_command,
  298. .dev_select = ata_std_dev_select,
  299. .bmdma_setup = ata_bmdma_setup,
  300. .bmdma_start = ata_bmdma_start,
  301. .bmdma_stop = ata_bmdma_stop,
  302. .bmdma_status = ata_bmdma_status,
  303. .qc_prep = ata_qc_prep,
  304. .qc_issue = ata_qc_issue_prot,
  305. .data_xfer = ata_data_xfer,
  306. .freeze = ata_bmdma_freeze,
  307. .thaw = ata_bmdma_thaw,
  308. .error_handler = piix_pata_error_handler,
  309. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  310. .cable_detect = ata_cable_40wire,
  311. .irq_clear = ata_bmdma_irq_clear,
  312. .irq_on = ata_irq_on,
  313. .port_start = ata_sff_port_start,
  314. };
  315. static const struct ata_port_operations ich_pata_ops = {
  316. .set_piomode = piix_set_piomode,
  317. .set_dmamode = ich_set_dmamode,
  318. .mode_filter = ata_pci_default_filter,
  319. .tf_load = ata_tf_load,
  320. .tf_read = ata_tf_read,
  321. .check_status = ata_check_status,
  322. .exec_command = ata_exec_command,
  323. .dev_select = ata_std_dev_select,
  324. .bmdma_setup = ata_bmdma_setup,
  325. .bmdma_start = ata_bmdma_start,
  326. .bmdma_stop = ata_bmdma_stop,
  327. .bmdma_status = ata_bmdma_status,
  328. .qc_prep = ata_qc_prep,
  329. .qc_issue = ata_qc_issue_prot,
  330. .data_xfer = ata_data_xfer,
  331. .freeze = ata_bmdma_freeze,
  332. .thaw = ata_bmdma_thaw,
  333. .error_handler = piix_pata_error_handler,
  334. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  335. .cable_detect = ich_pata_cable_detect,
  336. .irq_clear = ata_bmdma_irq_clear,
  337. .irq_on = ata_irq_on,
  338. .port_start = ata_sff_port_start,
  339. };
  340. static const struct ata_port_operations piix_sata_ops = {
  341. .tf_load = ata_tf_load,
  342. .tf_read = ata_tf_read,
  343. .check_status = ata_check_status,
  344. .exec_command = ata_exec_command,
  345. .dev_select = ata_std_dev_select,
  346. .bmdma_setup = ata_bmdma_setup,
  347. .bmdma_start = ata_bmdma_start,
  348. .bmdma_stop = ata_bmdma_stop,
  349. .bmdma_status = ata_bmdma_status,
  350. .qc_prep = ata_qc_prep,
  351. .qc_issue = ata_qc_issue_prot,
  352. .data_xfer = ata_data_xfer,
  353. .mode_filter = ata_pci_default_filter,
  354. .freeze = ata_bmdma_freeze,
  355. .thaw = ata_bmdma_thaw,
  356. .error_handler = ata_bmdma_error_handler,
  357. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  358. .irq_clear = ata_bmdma_irq_clear,
  359. .irq_on = ata_irq_on,
  360. .port_start = ata_sff_port_start,
  361. };
  362. static const struct ata_port_operations piix_vmw_ops = {
  363. .set_piomode = piix_set_piomode,
  364. .set_dmamode = piix_set_dmamode,
  365. .mode_filter = ata_pci_default_filter,
  366. .tf_load = ata_tf_load,
  367. .tf_read = ata_tf_read,
  368. .check_status = ata_check_status,
  369. .exec_command = ata_exec_command,
  370. .dev_select = ata_std_dev_select,
  371. .bmdma_setup = ata_bmdma_setup,
  372. .bmdma_start = ata_bmdma_start,
  373. .bmdma_stop = ata_bmdma_stop,
  374. .bmdma_status = piix_vmw_bmdma_status,
  375. .qc_prep = ata_qc_prep,
  376. .qc_issue = ata_qc_issue_prot,
  377. .data_xfer = ata_data_xfer,
  378. .freeze = ata_bmdma_freeze,
  379. .thaw = ata_bmdma_thaw,
  380. .error_handler = piix_pata_error_handler,
  381. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  382. .cable_detect = ata_cable_40wire,
  383. .irq_handler = ata_interrupt,
  384. .irq_clear = ata_bmdma_irq_clear,
  385. .irq_on = ata_irq_on,
  386. .port_start = ata_sff_port_start,
  387. };
  388. static const struct ata_port_operations piix_sidpr_sata_ops = {
  389. .tf_load = ata_tf_load,
  390. .tf_read = ata_tf_read,
  391. .check_status = ata_check_status,
  392. .exec_command = ata_exec_command,
  393. .dev_select = ata_std_dev_select,
  394. .bmdma_setup = ata_bmdma_setup,
  395. .bmdma_start = ata_bmdma_start,
  396. .bmdma_stop = ata_bmdma_stop,
  397. .bmdma_status = ata_bmdma_status,
  398. .qc_prep = ata_qc_prep,
  399. .qc_issue = ata_qc_issue_prot,
  400. .data_xfer = ata_data_xfer,
  401. .scr_read = piix_sidpr_scr_read,
  402. .scr_write = piix_sidpr_scr_write,
  403. .mode_filter = ata_pci_default_filter,
  404. .freeze = ata_bmdma_freeze,
  405. .thaw = ata_bmdma_thaw,
  406. .error_handler = piix_sidpr_error_handler,
  407. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  408. .irq_clear = ata_bmdma_irq_clear,
  409. .irq_on = ata_irq_on,
  410. .port_start = ata_sff_port_start,
  411. };
  412. static const struct piix_map_db ich5_map_db = {
  413. .mask = 0x7,
  414. .port_enable = 0x3,
  415. .map = {
  416. /* PM PS SM SS MAP */
  417. { P0, NA, P1, NA }, /* 000b */
  418. { P1, NA, P0, NA }, /* 001b */
  419. { RV, RV, RV, RV },
  420. { RV, RV, RV, RV },
  421. { P0, P1, IDE, IDE }, /* 100b */
  422. { P1, P0, IDE, IDE }, /* 101b */
  423. { IDE, IDE, P0, P1 }, /* 110b */
  424. { IDE, IDE, P1, P0 }, /* 111b */
  425. },
  426. };
  427. static const struct piix_map_db ich6_map_db = {
  428. .mask = 0x3,
  429. .port_enable = 0xf,
  430. .map = {
  431. /* PM PS SM SS MAP */
  432. { P0, P2, P1, P3 }, /* 00b */
  433. { IDE, IDE, P1, P3 }, /* 01b */
  434. { P0, P2, IDE, IDE }, /* 10b */
  435. { RV, RV, RV, RV },
  436. },
  437. };
  438. static const struct piix_map_db ich6m_map_db = {
  439. .mask = 0x3,
  440. .port_enable = 0x5,
  441. /* Map 01b isn't specified in the doc but some notebooks use
  442. * it anyway. MAP 01b have been spotted on both ICH6M and
  443. * ICH7M.
  444. */
  445. .map = {
  446. /* PM PS SM SS MAP */
  447. { P0, P2, NA, NA }, /* 00b */
  448. { IDE, IDE, P1, P3 }, /* 01b */
  449. { P0, P2, IDE, IDE }, /* 10b */
  450. { RV, RV, RV, RV },
  451. },
  452. };
  453. static const struct piix_map_db ich8_map_db = {
  454. .mask = 0x3,
  455. .port_enable = 0xf,
  456. .map = {
  457. /* PM PS SM SS MAP */
  458. { P0, P2, P1, P3 }, /* 00b (hardwired when in AHCI) */
  459. { RV, RV, RV, RV },
  460. { P0, P2, IDE, IDE }, /* 10b (IDE mode) */
  461. { RV, RV, RV, RV },
  462. },
  463. };
  464. static const struct piix_map_db ich8_2port_map_db = {
  465. .mask = 0x3,
  466. .port_enable = 0x3,
  467. .map = {
  468. /* PM PS SM SS MAP */
  469. { P0, NA, P1, NA }, /* 00b */
  470. { RV, RV, RV, RV }, /* 01b */
  471. { RV, RV, RV, RV }, /* 10b */
  472. { RV, RV, RV, RV },
  473. },
  474. };
  475. static const struct piix_map_db ich8m_apple_map_db = {
  476. .mask = 0x3,
  477. .port_enable = 0x1,
  478. .map = {
  479. /* PM PS SM SS MAP */
  480. { P0, NA, NA, NA }, /* 00b */
  481. { RV, RV, RV, RV },
  482. { P0, P2, IDE, IDE }, /* 10b */
  483. { RV, RV, RV, RV },
  484. },
  485. };
  486. static const struct piix_map_db tolapai_map_db = {
  487. .mask = 0x3,
  488. .port_enable = 0x3,
  489. .map = {
  490. /* PM PS SM SS MAP */
  491. { P0, NA, P1, NA }, /* 00b */
  492. { RV, RV, RV, RV }, /* 01b */
  493. { RV, RV, RV, RV }, /* 10b */
  494. { RV, RV, RV, RV },
  495. },
  496. };
  497. static const struct piix_map_db *piix_map_db_table[] = {
  498. [ich5_sata] = &ich5_map_db,
  499. [ich6_sata] = &ich6_map_db,
  500. [ich6_sata_ahci] = &ich6_map_db,
  501. [ich6m_sata_ahci] = &ich6m_map_db,
  502. [ich8_sata_ahci] = &ich8_map_db,
  503. [ich8_2port_sata] = &ich8_2port_map_db,
  504. [ich8m_apple_sata_ahci] = &ich8m_apple_map_db,
  505. [tolapai_sata_ahci] = &tolapai_map_db,
  506. };
  507. static struct ata_port_info piix_port_info[] = {
  508. [piix_pata_mwdma] = /* PIIX3 MWDMA only */
  509. {
  510. .flags = PIIX_PATA_FLAGS,
  511. .pio_mask = 0x1f, /* pio0-4 */
  512. .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
  513. .port_ops = &piix_pata_ops,
  514. },
  515. [piix_pata_33] = /* PIIX4 at 33MHz */
  516. {
  517. .flags = PIIX_PATA_FLAGS,
  518. .pio_mask = 0x1f, /* pio0-4 */
  519. .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
  520. .udma_mask = ATA_UDMA_MASK_40C,
  521. .port_ops = &piix_pata_ops,
  522. },
  523. [ich_pata_33] = /* ICH0 - ICH at 33Mhz*/
  524. {
  525. .flags = PIIX_PATA_FLAGS,
  526. .pio_mask = 0x1f, /* pio 0-4 */
  527. .mwdma_mask = 0x06, /* Check: maybe 0x07 */
  528. .udma_mask = ATA_UDMA2, /* UDMA33 */
  529. .port_ops = &ich_pata_ops,
  530. },
  531. [ich_pata_66] = /* ICH controllers up to 66MHz */
  532. {
  533. .flags = PIIX_PATA_FLAGS,
  534. .pio_mask = 0x1f, /* pio 0-4 */
  535. .mwdma_mask = 0x06, /* MWDMA0 is broken on chip */
  536. .udma_mask = ATA_UDMA4,
  537. .port_ops = &ich_pata_ops,
  538. },
  539. [ich_pata_100] =
  540. {
  541. .flags = PIIX_PATA_FLAGS | PIIX_FLAG_CHECKINTR,
  542. .pio_mask = 0x1f, /* pio0-4 */
  543. .mwdma_mask = 0x06, /* mwdma1-2 */
  544. .udma_mask = ATA_UDMA5, /* udma0-5 */
  545. .port_ops = &ich_pata_ops,
  546. },
  547. [ich5_sata] =
  548. {
  549. .flags = PIIX_SATA_FLAGS,
  550. .pio_mask = 0x1f, /* pio0-4 */
  551. .mwdma_mask = 0x07, /* mwdma0-2 */
  552. .udma_mask = ATA_UDMA6,
  553. .port_ops = &piix_sata_ops,
  554. },
  555. [ich6_sata] =
  556. {
  557. .flags = PIIX_SATA_FLAGS,
  558. .pio_mask = 0x1f, /* pio0-4 */
  559. .mwdma_mask = 0x07, /* mwdma0-2 */
  560. .udma_mask = ATA_UDMA6,
  561. .port_ops = &piix_sata_ops,
  562. },
  563. [ich6_sata_ahci] =
  564. {
  565. .flags = PIIX_SATA_FLAGS | PIIX_FLAG_AHCI,
  566. .pio_mask = 0x1f, /* pio0-4 */
  567. .mwdma_mask = 0x07, /* mwdma0-2 */
  568. .udma_mask = ATA_UDMA6,
  569. .port_ops = &piix_sata_ops,
  570. },
  571. [ich6m_sata_ahci] =
  572. {
  573. .flags = PIIX_SATA_FLAGS | PIIX_FLAG_AHCI,
  574. .pio_mask = 0x1f, /* pio0-4 */
  575. .mwdma_mask = 0x07, /* mwdma0-2 */
  576. .udma_mask = ATA_UDMA6,
  577. .port_ops = &piix_sata_ops,
  578. },
  579. [ich8_sata_ahci] =
  580. {
  581. .flags = PIIX_SATA_FLAGS | PIIX_FLAG_AHCI |
  582. PIIX_FLAG_SIDPR,
  583. .pio_mask = 0x1f, /* pio0-4 */
  584. .mwdma_mask = 0x07, /* mwdma0-2 */
  585. .udma_mask = ATA_UDMA6,
  586. .port_ops = &piix_sata_ops,
  587. },
  588. [ich8_2port_sata] =
  589. {
  590. .flags = PIIX_SATA_FLAGS | PIIX_FLAG_AHCI |
  591. PIIX_FLAG_SIDPR,
  592. .pio_mask = 0x1f, /* pio0-4 */
  593. .mwdma_mask = 0x07, /* mwdma0-2 */
  594. .udma_mask = ATA_UDMA6,
  595. .port_ops = &piix_sata_ops,
  596. },
  597. [tolapai_sata_ahci] =
  598. {
  599. .flags = PIIX_SATA_FLAGS | PIIX_FLAG_AHCI,
  600. .pio_mask = 0x1f, /* pio0-4 */
  601. .mwdma_mask = 0x07, /* mwdma0-2 */
  602. .udma_mask = ATA_UDMA6,
  603. .port_ops = &piix_sata_ops,
  604. },
  605. [ich8m_apple_sata_ahci] =
  606. {
  607. .flags = PIIX_SATA_FLAGS | PIIX_FLAG_AHCI |
  608. PIIX_FLAG_SIDPR,
  609. .pio_mask = 0x1f, /* pio0-4 */
  610. .mwdma_mask = 0x07, /* mwdma0-2 */
  611. .udma_mask = ATA_UDMA6,
  612. .port_ops = &piix_sata_ops,
  613. },
  614. [piix_pata_vmw] =
  615. {
  616. .flags = PIIX_PATA_FLAGS,
  617. .pio_mask = 0x1f, /* pio0-4 */
  618. .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
  619. .udma_mask = ATA_UDMA_MASK_40C,
  620. .port_ops = &piix_vmw_ops,
  621. },
  622. };
  623. static struct pci_bits piix_enable_bits[] = {
  624. { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
  625. { 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */
  626. };
  627. MODULE_AUTHOR("Andre Hedrick, Alan Cox, Andrzej Krzysztofowicz, Jeff Garzik");
  628. MODULE_DESCRIPTION("SCSI low-level driver for Intel PIIX/ICH ATA controllers");
  629. MODULE_LICENSE("GPL");
  630. MODULE_DEVICE_TABLE(pci, piix_pci_tbl);
  631. MODULE_VERSION(DRV_VERSION);
  632. struct ich_laptop {
  633. u16 device;
  634. u16 subvendor;
  635. u16 subdevice;
  636. };
  637. /*
  638. * List of laptops that use short cables rather than 80 wire
  639. */
  640. static const struct ich_laptop ich_laptop[] = {
  641. /* devid, subvendor, subdev */
  642. { 0x27DF, 0x0005, 0x0280 }, /* ICH7 on Acer 5602WLMi */
  643. { 0x27DF, 0x1025, 0x0102 }, /* ICH7 on Acer 5602aWLMi */
  644. { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */
  645. { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */
  646. { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */
  647. { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on ACER Aspire 2023WLMi */
  648. /* end marker */
  649. { 0, }
  650. };
  651. /**
  652. * ich_pata_cable_detect - Probe host controller cable detect info
  653. * @ap: Port for which cable detect info is desired
  654. *
  655. * Read 80c cable indicator from ATA PCI device's PCI config
  656. * register. This register is normally set by firmware (BIOS).
  657. *
  658. * LOCKING:
  659. * None (inherited from caller).
  660. */
  661. static int ich_pata_cable_detect(struct ata_port *ap)
  662. {
  663. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  664. const struct ich_laptop *lap = &ich_laptop[0];
  665. u8 tmp, mask;
  666. /* Check for specials - Acer Aspire 5602WLMi */
  667. while (lap->device) {
  668. if (lap->device == pdev->device &&
  669. lap->subvendor == pdev->subsystem_vendor &&
  670. lap->subdevice == pdev->subsystem_device)
  671. return ATA_CBL_PATA40_SHORT;
  672. lap++;
  673. }
  674. /* check BIOS cable detect results */
  675. mask = ap->port_no == 0 ? PIIX_80C_PRI : PIIX_80C_SEC;
  676. pci_read_config_byte(pdev, PIIX_IOCFG, &tmp);
  677. if ((tmp & mask) == 0)
  678. return ATA_CBL_PATA40;
  679. return ATA_CBL_PATA80;
  680. }
  681. /**
  682. * piix_pata_prereset - prereset for PATA host controller
  683. * @link: Target link
  684. * @deadline: deadline jiffies for the operation
  685. *
  686. * LOCKING:
  687. * None (inherited from caller).
  688. */
  689. static int piix_pata_prereset(struct ata_link *link, unsigned long deadline)
  690. {
  691. struct ata_port *ap = link->ap;
  692. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  693. if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no]))
  694. return -ENOENT;
  695. return ata_std_prereset(link, deadline);
  696. }
  697. static void piix_pata_error_handler(struct ata_port *ap)
  698. {
  699. ata_bmdma_drive_eh(ap, piix_pata_prereset, ata_std_softreset, NULL,
  700. ata_std_postreset);
  701. }
  702. /**
  703. * piix_set_piomode - Initialize host controller PATA PIO timings
  704. * @ap: Port whose timings we are configuring
  705. * @adev: um
  706. *
  707. * Set PIO mode for device, in host controller PCI config space.
  708. *
  709. * LOCKING:
  710. * None (inherited from caller).
  711. */
  712. static void piix_set_piomode(struct ata_port *ap, struct ata_device *adev)
  713. {
  714. unsigned int pio = adev->pio_mode - XFER_PIO_0;
  715. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  716. unsigned int is_slave = (adev->devno != 0);
  717. unsigned int master_port= ap->port_no ? 0x42 : 0x40;
  718. unsigned int slave_port = 0x44;
  719. u16 master_data;
  720. u8 slave_data;
  721. u8 udma_enable;
  722. int control = 0;
  723. /*
  724. * See Intel Document 298600-004 for the timing programing rules
  725. * for ICH controllers.
  726. */
  727. static const /* ISP RTC */
  728. u8 timings[][2] = { { 0, 0 },
  729. { 0, 0 },
  730. { 1, 0 },
  731. { 2, 1 },
  732. { 2, 3 }, };
  733. if (pio >= 2)
  734. control |= 1; /* TIME1 enable */
  735. if (ata_pio_need_iordy(adev))
  736. control |= 2; /* IE enable */
  737. /* Intel specifies that the PPE functionality is for disk only */
  738. if (adev->class == ATA_DEV_ATA)
  739. control |= 4; /* PPE enable */
  740. /* PIO configuration clears DTE unconditionally. It will be
  741. * programmed in set_dmamode which is guaranteed to be called
  742. * after set_piomode if any DMA mode is available.
  743. */
  744. pci_read_config_word(dev, master_port, &master_data);
  745. if (is_slave) {
  746. /* clear TIME1|IE1|PPE1|DTE1 */
  747. master_data &= 0xff0f;
  748. /* Enable SITRE (separate slave timing register) */
  749. master_data |= 0x4000;
  750. /* enable PPE1, IE1 and TIME1 as needed */
  751. master_data |= (control << 4);
  752. pci_read_config_byte(dev, slave_port, &slave_data);
  753. slave_data &= (ap->port_no ? 0x0f : 0xf0);
  754. /* Load the timing nibble for this slave */
  755. slave_data |= ((timings[pio][0] << 2) | timings[pio][1])
  756. << (ap->port_no ? 4 : 0);
  757. } else {
  758. /* clear ISP|RCT|TIME0|IE0|PPE0|DTE0 */
  759. master_data &= 0xccf0;
  760. /* Enable PPE, IE and TIME as appropriate */
  761. master_data |= control;
  762. /* load ISP and RCT */
  763. master_data |=
  764. (timings[pio][0] << 12) |
  765. (timings[pio][1] << 8);
  766. }
  767. pci_write_config_word(dev, master_port, master_data);
  768. if (is_slave)
  769. pci_write_config_byte(dev, slave_port, slave_data);
  770. /* Ensure the UDMA bit is off - it will be turned back on if
  771. UDMA is selected */
  772. if (ap->udma_mask) {
  773. pci_read_config_byte(dev, 0x48, &udma_enable);
  774. udma_enable &= ~(1 << (2 * ap->port_no + adev->devno));
  775. pci_write_config_byte(dev, 0x48, udma_enable);
  776. }
  777. }
  778. /**
  779. * do_pata_set_dmamode - Initialize host controller PATA PIO timings
  780. * @ap: Port whose timings we are configuring
  781. * @adev: Drive in question
  782. * @udma: udma mode, 0 - 6
  783. * @isich: set if the chip is an ICH device
  784. *
  785. * Set UDMA mode for device, in host controller PCI config space.
  786. *
  787. * LOCKING:
  788. * None (inherited from caller).
  789. */
  790. static void do_pata_set_dmamode(struct ata_port *ap, struct ata_device *adev, int isich)
  791. {
  792. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  793. u8 master_port = ap->port_no ? 0x42 : 0x40;
  794. u16 master_data;
  795. u8 speed = adev->dma_mode;
  796. int devid = adev->devno + 2 * ap->port_no;
  797. u8 udma_enable = 0;
  798. static const /* ISP RTC */
  799. u8 timings[][2] = { { 0, 0 },
  800. { 0, 0 },
  801. { 1, 0 },
  802. { 2, 1 },
  803. { 2, 3 }, };
  804. pci_read_config_word(dev, master_port, &master_data);
  805. if (ap->udma_mask)
  806. pci_read_config_byte(dev, 0x48, &udma_enable);
  807. if (speed >= XFER_UDMA_0) {
  808. unsigned int udma = adev->dma_mode - XFER_UDMA_0;
  809. u16 udma_timing;
  810. u16 ideconf;
  811. int u_clock, u_speed;
  812. /*
  813. * UDMA is handled by a combination of clock switching and
  814. * selection of dividers
  815. *
  816. * Handy rule: Odd modes are UDMATIMx 01, even are 02
  817. * except UDMA0 which is 00
  818. */
  819. u_speed = min(2 - (udma & 1), udma);
  820. if (udma == 5)
  821. u_clock = 0x1000; /* 100Mhz */
  822. else if (udma > 2)
  823. u_clock = 1; /* 66Mhz */
  824. else
  825. u_clock = 0; /* 33Mhz */
  826. udma_enable |= (1 << devid);
  827. /* Load the CT/RP selection */
  828. pci_read_config_word(dev, 0x4A, &udma_timing);
  829. udma_timing &= ~(3 << (4 * devid));
  830. udma_timing |= u_speed << (4 * devid);
  831. pci_write_config_word(dev, 0x4A, udma_timing);
  832. if (isich) {
  833. /* Select a 33/66/100Mhz clock */
  834. pci_read_config_word(dev, 0x54, &ideconf);
  835. ideconf &= ~(0x1001 << devid);
  836. ideconf |= u_clock << devid;
  837. /* For ICH or later we should set bit 10 for better
  838. performance (WR_PingPong_En) */
  839. pci_write_config_word(dev, 0x54, ideconf);
  840. }
  841. } else {
  842. /*
  843. * MWDMA is driven by the PIO timings. We must also enable
  844. * IORDY unconditionally along with TIME1. PPE has already
  845. * been set when the PIO timing was set.
  846. */
  847. unsigned int mwdma = adev->dma_mode - XFER_MW_DMA_0;
  848. unsigned int control;
  849. u8 slave_data;
  850. const unsigned int needed_pio[3] = {
  851. XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
  852. };
  853. int pio = needed_pio[mwdma] - XFER_PIO_0;
  854. control = 3; /* IORDY|TIME1 */
  855. /* If the drive MWDMA is faster than it can do PIO then
  856. we must force PIO into PIO0 */
  857. if (adev->pio_mode < needed_pio[mwdma])
  858. /* Enable DMA timing only */
  859. control |= 8; /* PIO cycles in PIO0 */
  860. if (adev->devno) { /* Slave */
  861. master_data &= 0xFF4F; /* Mask out IORDY|TIME1|DMAONLY */
  862. master_data |= control << 4;
  863. pci_read_config_byte(dev, 0x44, &slave_data);
  864. slave_data &= (ap->port_no ? 0x0f : 0xf0);
  865. /* Load the matching timing */
  866. slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << (ap->port_no ? 4 : 0);
  867. pci_write_config_byte(dev, 0x44, slave_data);
  868. } else { /* Master */
  869. master_data &= 0xCCF4; /* Mask out IORDY|TIME1|DMAONLY
  870. and master timing bits */
  871. master_data |= control;
  872. master_data |=
  873. (timings[pio][0] << 12) |
  874. (timings[pio][1] << 8);
  875. }
  876. if (ap->udma_mask) {
  877. udma_enable &= ~(1 << devid);
  878. pci_write_config_word(dev, master_port, master_data);
  879. }
  880. }
  881. /* Don't scribble on 0x48 if the controller does not support UDMA */
  882. if (ap->udma_mask)
  883. pci_write_config_byte(dev, 0x48, udma_enable);
  884. }
  885. /**
  886. * piix_set_dmamode - Initialize host controller PATA DMA timings
  887. * @ap: Port whose timings we are configuring
  888. * @adev: um
  889. *
  890. * Set MW/UDMA mode for device, in host controller PCI config space.
  891. *
  892. * LOCKING:
  893. * None (inherited from caller).
  894. */
  895. static void piix_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  896. {
  897. do_pata_set_dmamode(ap, adev, 0);
  898. }
  899. /**
  900. * ich_set_dmamode - Initialize host controller PATA DMA timings
  901. * @ap: Port whose timings we are configuring
  902. * @adev: um
  903. *
  904. * Set MW/UDMA mode for device, in host controller PCI config space.
  905. *
  906. * LOCKING:
  907. * None (inherited from caller).
  908. */
  909. static void ich_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  910. {
  911. do_pata_set_dmamode(ap, adev, 1);
  912. }
  913. /*
  914. * Serial ATA Index/Data Pair Superset Registers access
  915. *
  916. * Beginning from ICH8, there's a sane way to access SCRs using index
  917. * and data register pair located at BAR5. This creates an
  918. * interesting problem of mapping two SCRs to one port.
  919. *
  920. * Although they have separate SCRs, the master and slave aren't
  921. * independent enough to be treated as separate links - e.g. softreset
  922. * resets both. Also, there's no protocol defined for hard resetting
  923. * singled device sharing the virtual port (no defined way to acquire
  924. * device signature). This is worked around by merging the SCR values
  925. * into one sensible value and requesting follow-up SRST after
  926. * hardreset.
  927. *
  928. * SCR merging is perfomed in nibbles which is the unit contents in
  929. * SCRs are organized. If two values are equal, the value is used.
  930. * When they differ, merge table which lists precedence of possible
  931. * values is consulted and the first match or the last entry when
  932. * nothing matches is used. When there's no merge table for the
  933. * specific nibble, value from the first port is used.
  934. */
  935. static const int piix_sidx_map[] = {
  936. [SCR_STATUS] = 0,
  937. [SCR_ERROR] = 2,
  938. [SCR_CONTROL] = 1,
  939. };
  940. static void piix_sidpr_sel(struct ata_device *dev, unsigned int reg)
  941. {
  942. struct ata_port *ap = dev->link->ap;
  943. struct piix_host_priv *hpriv = ap->host->private_data;
  944. iowrite32(((ap->port_no * 2 + dev->devno) << 8) | piix_sidx_map[reg],
  945. hpriv->sidpr + PIIX_SIDPR_IDX);
  946. }
  947. static int piix_sidpr_read(struct ata_device *dev, unsigned int reg)
  948. {
  949. struct piix_host_priv *hpriv = dev->link->ap->host->private_data;
  950. piix_sidpr_sel(dev, reg);
  951. return ioread32(hpriv->sidpr + PIIX_SIDPR_DATA);
  952. }
  953. static void piix_sidpr_write(struct ata_device *dev, unsigned int reg, u32 val)
  954. {
  955. struct piix_host_priv *hpriv = dev->link->ap->host->private_data;
  956. piix_sidpr_sel(dev, reg);
  957. iowrite32(val, hpriv->sidpr + PIIX_SIDPR_DATA);
  958. }
  959. static u32 piix_merge_scr(u32 val0, u32 val1, const int * const *merge_tbl)
  960. {
  961. u32 val = 0;
  962. int i, mi;
  963. for (i = 0, mi = 0; i < 32 / 4; i++) {
  964. u8 c0 = (val0 >> (i * 4)) & 0xf;
  965. u8 c1 = (val1 >> (i * 4)) & 0xf;
  966. u8 merged = c0;
  967. const int *cur;
  968. /* if no merge preference, assume the first value */
  969. cur = merge_tbl[mi];
  970. if (!cur)
  971. goto done;
  972. mi++;
  973. /* if two values equal, use it */
  974. if (c0 == c1)
  975. goto done;
  976. /* choose the first match or the last from the merge table */
  977. while (*cur != -1) {
  978. if (c0 == *cur || c1 == *cur)
  979. break;
  980. cur++;
  981. }
  982. if (*cur == -1)
  983. cur--;
  984. merged = *cur;
  985. done:
  986. val |= merged << (i * 4);
  987. }
  988. return val;
  989. }
  990. static int piix_sidpr_scr_read(struct ata_port *ap, unsigned int reg, u32 *val)
  991. {
  992. const int * const sstatus_merge_tbl[] = {
  993. /* DET */ (const int []){ 1, 3, 0, 4, 3, -1 },
  994. /* SPD */ (const int []){ 2, 1, 0, -1 },
  995. /* IPM */ (const int []){ 6, 2, 1, 0, -1 },
  996. NULL,
  997. };
  998. const int * const scontrol_merge_tbl[] = {
  999. /* DET */ (const int []){ 1, 0, 4, 0, -1 },
  1000. /* SPD */ (const int []){ 0, 2, 1, 0, -1 },
  1001. /* IPM */ (const int []){ 0, 1, 2, 3, 0, -1 },
  1002. NULL,
  1003. };
  1004. u32 v0, v1;
  1005. if (reg >= ARRAY_SIZE(piix_sidx_map))
  1006. return -EINVAL;
  1007. if (!(ap->flags & ATA_FLAG_SLAVE_POSS)) {
  1008. *val = piix_sidpr_read(&ap->link.device[0], reg);
  1009. return 0;
  1010. }
  1011. v0 = piix_sidpr_read(&ap->link.device[0], reg);
  1012. v1 = piix_sidpr_read(&ap->link.device[1], reg);
  1013. switch (reg) {
  1014. case SCR_STATUS:
  1015. *val = piix_merge_scr(v0, v1, sstatus_merge_tbl);
  1016. break;
  1017. case SCR_ERROR:
  1018. *val = v0 | v1;
  1019. break;
  1020. case SCR_CONTROL:
  1021. *val = piix_merge_scr(v0, v1, scontrol_merge_tbl);
  1022. break;
  1023. }
  1024. return 0;
  1025. }
  1026. static int piix_sidpr_scr_write(struct ata_port *ap, unsigned int reg, u32 val)
  1027. {
  1028. if (reg >= ARRAY_SIZE(piix_sidx_map))
  1029. return -EINVAL;
  1030. piix_sidpr_write(&ap->link.device[0], reg, val);
  1031. if (ap->flags & ATA_FLAG_SLAVE_POSS)
  1032. piix_sidpr_write(&ap->link.device[1], reg, val);
  1033. return 0;
  1034. }
  1035. static int piix_sidpr_hardreset(struct ata_link *link, unsigned int *class,
  1036. unsigned long deadline)
  1037. {
  1038. const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
  1039. int rc;
  1040. /* do hardreset */
  1041. rc = sata_link_hardreset(link, timing, deadline);
  1042. if (rc) {
  1043. ata_link_printk(link, KERN_ERR,
  1044. "COMRESET failed (errno=%d)\n", rc);
  1045. return rc;
  1046. }
  1047. /* TODO: phy layer with polling, timeouts, etc. */
  1048. if (ata_link_offline(link)) {
  1049. *class = ATA_DEV_NONE;
  1050. return 0;
  1051. }
  1052. return -EAGAIN;
  1053. }
  1054. static void piix_sidpr_error_handler(struct ata_port *ap)
  1055. {
  1056. ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset,
  1057. piix_sidpr_hardreset, ata_std_postreset);
  1058. }
  1059. #ifdef CONFIG_PM
  1060. static int piix_broken_suspend(void)
  1061. {
  1062. static const struct dmi_system_id sysids[] = {
  1063. {
  1064. .ident = "TECRA M3",
  1065. .matches = {
  1066. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1067. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M3"),
  1068. },
  1069. },
  1070. {
  1071. .ident = "TECRA M3",
  1072. .matches = {
  1073. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1074. DMI_MATCH(DMI_PRODUCT_NAME, "Tecra M3"),
  1075. },
  1076. },
  1077. {
  1078. .ident = "TECRA M4",
  1079. .matches = {
  1080. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1081. DMI_MATCH(DMI_PRODUCT_NAME, "Tecra M4"),
  1082. },
  1083. },
  1084. {
  1085. .ident = "TECRA M5",
  1086. .matches = {
  1087. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1088. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M5"),
  1089. },
  1090. },
  1091. {
  1092. .ident = "TECRA M6",
  1093. .matches = {
  1094. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1095. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M6"),
  1096. },
  1097. },
  1098. {
  1099. .ident = "TECRA M7",
  1100. .matches = {
  1101. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1102. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M7"),
  1103. },
  1104. },
  1105. {
  1106. .ident = "TECRA A8",
  1107. .matches = {
  1108. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1109. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A8"),
  1110. },
  1111. },
  1112. {
  1113. .ident = "Satellite R20",
  1114. .matches = {
  1115. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1116. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite R20"),
  1117. },
  1118. },
  1119. {
  1120. .ident = "Satellite R25",
  1121. .matches = {
  1122. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1123. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite R25"),
  1124. },
  1125. },
  1126. {
  1127. .ident = "Satellite U200",
  1128. .matches = {
  1129. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1130. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite U200"),
  1131. },
  1132. },
  1133. {
  1134. .ident = "Satellite U200",
  1135. .matches = {
  1136. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1137. DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE U200"),
  1138. },
  1139. },
  1140. {
  1141. .ident = "Satellite Pro U200",
  1142. .matches = {
  1143. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1144. DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE PRO U200"),
  1145. },
  1146. },
  1147. {
  1148. .ident = "Satellite U205",
  1149. .matches = {
  1150. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1151. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite U205"),
  1152. },
  1153. },
  1154. {
  1155. .ident = "SATELLITE U205",
  1156. .matches = {
  1157. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1158. DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE U205"),
  1159. },
  1160. },
  1161. {
  1162. .ident = "Portege M500",
  1163. .matches = {
  1164. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  1165. DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M500"),
  1166. },
  1167. },
  1168. { } /* terminate list */
  1169. };
  1170. static const char *oemstrs[] = {
  1171. "Tecra M3,",
  1172. };
  1173. int i;
  1174. if (dmi_check_system(sysids))
  1175. return 1;
  1176. for (i = 0; i < ARRAY_SIZE(oemstrs); i++)
  1177. if (dmi_find_device(DMI_DEV_TYPE_OEM_STRING, oemstrs[i], NULL))
  1178. return 1;
  1179. return 0;
  1180. }
  1181. static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
  1182. {
  1183. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  1184. unsigned long flags;
  1185. int rc = 0;
  1186. rc = ata_host_suspend(host, mesg);
  1187. if (rc)
  1188. return rc;
  1189. /* Some braindamaged ACPI suspend implementations expect the
  1190. * controller to be awake on entry; otherwise, it burns cpu
  1191. * cycles and power trying to do something to the sleeping
  1192. * beauty.
  1193. */
  1194. if (piix_broken_suspend() && (mesg.event & PM_EVENT_SLEEP)) {
  1195. pci_save_state(pdev);
  1196. /* mark its power state as "unknown", since we don't
  1197. * know if e.g. the BIOS will change its device state
  1198. * when we suspend.
  1199. */
  1200. if (pdev->current_state == PCI_D0)
  1201. pdev->current_state = PCI_UNKNOWN;
  1202. /* tell resume that it's waking up from broken suspend */
  1203. spin_lock_irqsave(&host->lock, flags);
  1204. host->flags |= PIIX_HOST_BROKEN_SUSPEND;
  1205. spin_unlock_irqrestore(&host->lock, flags);
  1206. } else
  1207. ata_pci_device_do_suspend(pdev, mesg);
  1208. return 0;
  1209. }
  1210. static int piix_pci_device_resume(struct pci_dev *pdev)
  1211. {
  1212. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  1213. unsigned long flags;
  1214. int rc;
  1215. if (host->flags & PIIX_HOST_BROKEN_SUSPEND) {
  1216. spin_lock_irqsave(&host->lock, flags);
  1217. host->flags &= ~PIIX_HOST_BROKEN_SUSPEND;
  1218. spin_unlock_irqrestore(&host->lock, flags);
  1219. pci_set_power_state(pdev, PCI_D0);
  1220. pci_restore_state(pdev);
  1221. /* PCI device wasn't disabled during suspend. Use
  1222. * pci_reenable_device() to avoid affecting the enable
  1223. * count.
  1224. */
  1225. rc = pci_reenable_device(pdev);
  1226. if (rc)
  1227. dev_printk(KERN_ERR, &pdev->dev, "failed to enable "
  1228. "device after resume (%d)\n", rc);
  1229. } else
  1230. rc = ata_pci_device_do_resume(pdev);
  1231. if (rc == 0)
  1232. ata_host_resume(host);
  1233. return rc;
  1234. }
  1235. #endif
  1236. static u8 piix_vmw_bmdma_status(struct ata_port *ap)
  1237. {
  1238. return ata_bmdma_status(ap) & ~ATA_DMA_ERR;
  1239. }
  1240. #define AHCI_PCI_BAR 5
  1241. #define AHCI_GLOBAL_CTL 0x04
  1242. #define AHCI_ENABLE (1 << 31)
  1243. static int piix_disable_ahci(struct pci_dev *pdev)
  1244. {
  1245. void __iomem *mmio;
  1246. u32 tmp;
  1247. int rc = 0;
  1248. /* BUG: pci_enable_device has not yet been called. This
  1249. * works because this device is usually set up by BIOS.
  1250. */
  1251. if (!pci_resource_start(pdev, AHCI_PCI_BAR) ||
  1252. !pci_resource_len(pdev, AHCI_PCI_BAR))
  1253. return 0;
  1254. mmio = pci_iomap(pdev, AHCI_PCI_BAR, 64);
  1255. if (!mmio)
  1256. return -ENOMEM;
  1257. tmp = ioread32(mmio + AHCI_GLOBAL_CTL);
  1258. if (tmp & AHCI_ENABLE) {
  1259. tmp &= ~AHCI_ENABLE;
  1260. iowrite32(tmp, mmio + AHCI_GLOBAL_CTL);
  1261. tmp = ioread32(mmio + AHCI_GLOBAL_CTL);
  1262. if (tmp & AHCI_ENABLE)
  1263. rc = -EIO;
  1264. }
  1265. pci_iounmap(pdev, mmio);
  1266. return rc;
  1267. }
  1268. /**
  1269. * piix_check_450nx_errata - Check for problem 450NX setup
  1270. * @ata_dev: the PCI device to check
  1271. *
  1272. * Check for the present of 450NX errata #19 and errata #25. If
  1273. * they are found return an error code so we can turn off DMA
  1274. */
  1275. static int __devinit piix_check_450nx_errata(struct pci_dev *ata_dev)
  1276. {
  1277. struct pci_dev *pdev = NULL;
  1278. u16 cfg;
  1279. int no_piix_dma = 0;
  1280. while ((pdev = pci_get_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, pdev)) != NULL) {
  1281. /* Look for 450NX PXB. Check for problem configurations
  1282. A PCI quirk checks bit 6 already */
  1283. pci_read_config_word(pdev, 0x41, &cfg);
  1284. /* Only on the original revision: IDE DMA can hang */
  1285. if (pdev->revision == 0x00)
  1286. no_piix_dma = 1;
  1287. /* On all revisions below 5 PXB bus lock must be disabled for IDE */
  1288. else if (cfg & (1<<14) && pdev->revision < 5)
  1289. no_piix_dma = 2;
  1290. }
  1291. if (no_piix_dma)
  1292. dev_printk(KERN_WARNING, &ata_dev->dev, "450NX errata present, disabling IDE DMA.\n");
  1293. if (no_piix_dma == 2)
  1294. dev_printk(KERN_WARNING, &ata_dev->dev, "A BIOS update may resolve this.\n");
  1295. return no_piix_dma;
  1296. }
  1297. static void __devinit piix_init_pcs(struct ata_host *host,
  1298. const struct piix_map_db *map_db)
  1299. {
  1300. struct pci_dev *pdev = to_pci_dev(host->dev);
  1301. u16 pcs, new_pcs;
  1302. pci_read_config_word(pdev, ICH5_PCS, &pcs);
  1303. new_pcs = pcs | map_db->port_enable;
  1304. if (new_pcs != pcs) {
  1305. DPRINTK("updating PCS from 0x%x to 0x%x\n", pcs, new_pcs);
  1306. pci_write_config_word(pdev, ICH5_PCS, new_pcs);
  1307. msleep(150);
  1308. }
  1309. }
  1310. static const int *__devinit piix_init_sata_map(struct pci_dev *pdev,
  1311. struct ata_port_info *pinfo,
  1312. const struct piix_map_db *map_db)
  1313. {
  1314. const int *map;
  1315. int i, invalid_map = 0;
  1316. u8 map_value;
  1317. pci_read_config_byte(pdev, ICH5_PMR, &map_value);
  1318. map = map_db->map[map_value & map_db->mask];
  1319. dev_printk(KERN_INFO, &pdev->dev, "MAP [");
  1320. for (i = 0; i < 4; i++) {
  1321. switch (map[i]) {
  1322. case RV:
  1323. invalid_map = 1;
  1324. printk(" XX");
  1325. break;
  1326. case NA:
  1327. printk(" --");
  1328. break;
  1329. case IDE:
  1330. WARN_ON((i & 1) || map[i + 1] != IDE);
  1331. pinfo[i / 2] = piix_port_info[ich_pata_100];
  1332. i++;
  1333. printk(" IDE IDE");
  1334. break;
  1335. default:
  1336. printk(" P%d", map[i]);
  1337. if (i & 1)
  1338. pinfo[i / 2].flags |= ATA_FLAG_SLAVE_POSS;
  1339. break;
  1340. }
  1341. }
  1342. printk(" ]\n");
  1343. if (invalid_map)
  1344. dev_printk(KERN_ERR, &pdev->dev,
  1345. "invalid MAP value %u\n", map_value);
  1346. return map;
  1347. }
  1348. static void __devinit piix_init_sidpr(struct ata_host *host)
  1349. {
  1350. struct pci_dev *pdev = to_pci_dev(host->dev);
  1351. struct piix_host_priv *hpriv = host->private_data;
  1352. int i;
  1353. /* check for availability */
  1354. for (i = 0; i < 4; i++)
  1355. if (hpriv->map[i] == IDE)
  1356. return;
  1357. if (!(host->ports[0]->flags & PIIX_FLAG_SIDPR))
  1358. return;
  1359. if (pci_resource_start(pdev, PIIX_SIDPR_BAR) == 0 ||
  1360. pci_resource_len(pdev, PIIX_SIDPR_BAR) != PIIX_SIDPR_LEN)
  1361. return;
  1362. if (pcim_iomap_regions(pdev, 1 << PIIX_SIDPR_BAR, DRV_NAME))
  1363. return;
  1364. hpriv->sidpr = pcim_iomap_table(pdev)[PIIX_SIDPR_BAR];
  1365. host->ports[0]->ops = &piix_sidpr_sata_ops;
  1366. host->ports[1]->ops = &piix_sidpr_sata_ops;
  1367. }
  1368. static void piix_iocfg_bit18_quirk(struct pci_dev *pdev)
  1369. {
  1370. static const struct dmi_system_id sysids[] = {
  1371. {
  1372. /* Clevo M570U sets IOCFG bit 18 if the cdrom
  1373. * isn't used to boot the system which
  1374. * disables the channel.
  1375. */
  1376. .ident = "M570U",
  1377. .matches = {
  1378. DMI_MATCH(DMI_SYS_VENDOR, "Clevo Co."),
  1379. DMI_MATCH(DMI_PRODUCT_NAME, "M570U"),
  1380. },
  1381. },
  1382. { } /* terminate list */
  1383. };
  1384. u32 iocfg;
  1385. if (!dmi_check_system(sysids))
  1386. return;
  1387. /* The datasheet says that bit 18 is NOOP but certain systems
  1388. * seem to use it to disable a channel. Clear the bit on the
  1389. * affected systems.
  1390. */
  1391. pci_read_config_dword(pdev, PIIX_IOCFG, &iocfg);
  1392. if (iocfg & (1 << 18)) {
  1393. dev_printk(KERN_INFO, &pdev->dev,
  1394. "applying IOCFG bit18 quirk\n");
  1395. iocfg &= ~(1 << 18);
  1396. pci_write_config_dword(pdev, PIIX_IOCFG, iocfg);
  1397. }
  1398. }
  1399. /**
  1400. * piix_init_one - Register PIIX ATA PCI device with kernel services
  1401. * @pdev: PCI device to register
  1402. * @ent: Entry in piix_pci_tbl matching with @pdev
  1403. *
  1404. * Called from kernel PCI layer. We probe for combined mode (sigh),
  1405. * and then hand over control to libata, for it to do the rest.
  1406. *
  1407. * LOCKING:
  1408. * Inherited from PCI layer (may sleep).
  1409. *
  1410. * RETURNS:
  1411. * Zero on success, or -ERRNO value.
  1412. */
  1413. static int __devinit piix_init_one(struct pci_dev *pdev,
  1414. const struct pci_device_id *ent)
  1415. {
  1416. static int printed_version;
  1417. struct device *dev = &pdev->dev;
  1418. struct ata_port_info port_info[2];
  1419. const struct ata_port_info *ppi[] = { &port_info[0], &port_info[1] };
  1420. unsigned long port_flags;
  1421. struct ata_host *host;
  1422. struct piix_host_priv *hpriv;
  1423. int rc;
  1424. if (!printed_version++)
  1425. dev_printk(KERN_DEBUG, &pdev->dev,
  1426. "version " DRV_VERSION "\n");
  1427. /* no hotplugging support (FIXME) */
  1428. if (!in_module_init)
  1429. return -ENODEV;
  1430. port_info[0] = piix_port_info[ent->driver_data];
  1431. port_info[1] = piix_port_info[ent->driver_data];
  1432. port_flags = port_info[0].flags;
  1433. /* enable device and prepare host */
  1434. rc = pcim_enable_device(pdev);
  1435. if (rc)
  1436. return rc;
  1437. /* SATA map init can change port_info, do it before prepping host */
  1438. hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
  1439. if (!hpriv)
  1440. return -ENOMEM;
  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_prepare_sff_host(pdev, ppi, &host);
  1445. if (rc)
  1446. return rc;
  1447. host->private_data = hpriv;
  1448. /* initialize controller */
  1449. if (port_flags & PIIX_FLAG_AHCI) {
  1450. u8 tmp;
  1451. pci_read_config_byte(pdev, PIIX_SCC, &tmp);
  1452. if (tmp == PIIX_AHCI_DEVICE) {
  1453. rc = piix_disable_ahci(pdev);
  1454. if (rc)
  1455. return rc;
  1456. }
  1457. }
  1458. if (port_flags & ATA_FLAG_SATA) {
  1459. piix_init_pcs(host, piix_map_db_table[ent->driver_data]);
  1460. piix_init_sidpr(host);
  1461. }
  1462. /* apply IOCFG bit18 quirk */
  1463. piix_iocfg_bit18_quirk(pdev);
  1464. /* On ICH5, some BIOSen disable the interrupt using the
  1465. * PCI_COMMAND_INTX_DISABLE bit added in PCI 2.3.
  1466. * On ICH6, this bit has the same effect, but only when
  1467. * MSI is disabled (and it is disabled, as we don't use
  1468. * message-signalled interrupts currently).
  1469. */
  1470. if (port_flags & PIIX_FLAG_CHECKINTR)
  1471. pci_intx(pdev, 1);
  1472. if (piix_check_450nx_errata(pdev)) {
  1473. /* This writes into the master table but it does not
  1474. really matter for this errata as we will apply it to
  1475. all the PIIX devices on the board */
  1476. host->ports[0]->mwdma_mask = 0;
  1477. host->ports[0]->udma_mask = 0;
  1478. host->ports[1]->mwdma_mask = 0;
  1479. host->ports[1]->udma_mask = 0;
  1480. }
  1481. pci_set_master(pdev);
  1482. return ata_pci_activate_sff_host(host, ata_interrupt, &piix_sht);
  1483. }
  1484. static int __init piix_init(void)
  1485. {
  1486. int rc;
  1487. DPRINTK("pci_register_driver\n");
  1488. rc = pci_register_driver(&piix_pci_driver);
  1489. if (rc)
  1490. return rc;
  1491. in_module_init = 0;
  1492. DPRINTK("done\n");
  1493. return 0;
  1494. }
  1495. static void __exit piix_exit(void)
  1496. {
  1497. pci_unregister_driver(&piix_pci_driver);
  1498. }
  1499. module_init(piix_init);
  1500. module_exit(piix_exit);