ata_piix.c 46 KB

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