ata_piix.c 40 KB

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