PageRenderTime 175ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/ata/ata_piix.c

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