ata_piix.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /*
  2. ata_piix.c - Intel PATA/SATA controllers
  3. Maintained by: Jeff Garzik <jgarzik@pobox.com>
  4. Please ALWAYS copy linux-ide@vger.kernel.org
  5. on emails.
  6. Copyright 2003-2004 Red Hat Inc
  7. Copyright 2003-2004 Jeff Garzik
  8. Copyright header from piix.c:
  9. Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer
  10. Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
  11. Copyright (C) 2003 Red Hat Inc <alan@redhat.com>
  12. May be copied or modified under the terms of the GNU General Public License
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/pci.h>
  17. #include <linux/init.h>
  18. #include <linux/blkdev.h>
  19. #include <linux/delay.h>
  20. #include "scsi.h"
  21. #include <scsi/scsi_host.h>
  22. #include <linux/libata.h>
  23. #define DRV_NAME "ata_piix"
  24. #define DRV_VERSION "1.03"
  25. enum {
  26. PIIX_IOCFG = 0x54, /* IDE I/O configuration register */
  27. ICH5_PMR = 0x90, /* port mapping register */
  28. ICH5_PCS = 0x92, /* port control and status */
  29. PIIX_FLAG_AHCI = (1 << 28), /* AHCI possible */
  30. PIIX_FLAG_CHECKINTR = (1 << 29), /* make sure PCI INTx enabled */
  31. PIIX_FLAG_COMBINED = (1 << 30), /* combined mode possible */
  32. /* combined mode. if set, PATA is channel 0.
  33. * if clear, PATA is channel 1.
  34. */
  35. PIIX_COMB_PATA_P0 = (1 << 1),
  36. PIIX_COMB = (1 << 2), /* combined mode enabled? */
  37. PIIX_PORT_PRESENT = (1 << 0),
  38. PIIX_PORT_ENABLED = (1 << 4),
  39. PIIX_80C_PRI = (1 << 5) | (1 << 4),
  40. PIIX_80C_SEC = (1 << 7) | (1 << 6),
  41. ich5_pata = 0,
  42. ich5_sata = 1,
  43. piix4_pata = 2,
  44. ich6_sata = 3,
  45. ich6_sata_rm = 4,
  46. ich7_sata = 5,
  47. esb2_sata = 6,
  48. };
  49. static int piix_init_one (struct pci_dev *pdev,
  50. const struct pci_device_id *ent);
  51. static void piix_pata_phy_reset(struct ata_port *ap);
  52. static void piix_sata_phy_reset(struct ata_port *ap);
  53. static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev);
  54. static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev);
  55. static unsigned int in_module_init = 1;
  56. static struct pci_device_id piix_pci_tbl[] = {
  57. #ifdef ATA_ENABLE_PATA
  58. { 0x8086, 0x7111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix4_pata },
  59. { 0x8086, 0x24db, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_pata },
  60. { 0x8086, 0x25a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_pata },
  61. #endif
  62. /* NOTE: The following PCI ids must be kept in sync with the
  63. * list in drivers/pci/quirks.c.
  64. */
  65. { 0x8086, 0x24d1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  66. { 0x8086, 0x24df, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  67. { 0x8086, 0x25a3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  68. { 0x8086, 0x25b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  69. { 0x8086, 0x2651, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata },
  70. { 0x8086, 0x2652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_rm },
  71. { 0x8086, 0x2653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_rm },
  72. { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich7_sata },
  73. { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich7_sata },
  74. { 0x8086, 0x2680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, esb2_sata },
  75. { } /* terminate list */
  76. };
  77. static struct pci_driver piix_pci_driver = {
  78. .name = DRV_NAME,
  79. .id_table = piix_pci_tbl,
  80. .probe = piix_init_one,
  81. .remove = ata_pci_remove_one,
  82. };
  83. static Scsi_Host_Template piix_sht = {
  84. .module = THIS_MODULE,
  85. .name = DRV_NAME,
  86. .ioctl = ata_scsi_ioctl,
  87. .queuecommand = ata_scsi_queuecmd,
  88. .eh_strategy_handler = ata_scsi_error,
  89. .can_queue = ATA_DEF_QUEUE,
  90. .this_id = ATA_SHT_THIS_ID,
  91. .sg_tablesize = LIBATA_MAX_PRD,
  92. .max_sectors = ATA_MAX_SECTORS,
  93. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  94. .emulated = ATA_SHT_EMULATED,
  95. .use_clustering = ATA_SHT_USE_CLUSTERING,
  96. .proc_name = DRV_NAME,
  97. .dma_boundary = ATA_DMA_BOUNDARY,
  98. .slave_configure = ata_scsi_slave_config,
  99. .bios_param = ata_std_bios_param,
  100. .ordered_flush = 1,
  101. };
  102. static struct ata_port_operations piix_pata_ops = {
  103. .port_disable = ata_port_disable,
  104. .set_piomode = piix_set_piomode,
  105. .set_dmamode = piix_set_dmamode,
  106. .tf_load = ata_tf_load,
  107. .tf_read = ata_tf_read,
  108. .check_status = ata_check_status,
  109. .exec_command = ata_exec_command,
  110. .dev_select = ata_std_dev_select,
  111. .phy_reset = piix_pata_phy_reset,
  112. .bmdma_setup = ata_bmdma_setup,
  113. .bmdma_start = ata_bmdma_start,
  114. .bmdma_stop = ata_bmdma_stop,
  115. .bmdma_status = ata_bmdma_status,
  116. .qc_prep = ata_qc_prep,
  117. .qc_issue = ata_qc_issue_prot,
  118. .eng_timeout = ata_eng_timeout,
  119. .irq_handler = ata_interrupt,
  120. .irq_clear = ata_bmdma_irq_clear,
  121. .port_start = ata_port_start,
  122. .port_stop = ata_port_stop,
  123. .host_stop = ata_host_stop,
  124. };
  125. static struct ata_port_operations piix_sata_ops = {
  126. .port_disable = ata_port_disable,
  127. .tf_load = ata_tf_load,
  128. .tf_read = ata_tf_read,
  129. .check_status = ata_check_status,
  130. .exec_command = ata_exec_command,
  131. .dev_select = ata_std_dev_select,
  132. .phy_reset = piix_sata_phy_reset,
  133. .bmdma_setup = ata_bmdma_setup,
  134. .bmdma_start = ata_bmdma_start,
  135. .bmdma_stop = ata_bmdma_stop,
  136. .bmdma_status = ata_bmdma_status,
  137. .qc_prep = ata_qc_prep,
  138. .qc_issue = ata_qc_issue_prot,
  139. .eng_timeout = ata_eng_timeout,
  140. .irq_handler = ata_interrupt,
  141. .irq_clear = ata_bmdma_irq_clear,
  142. .port_start = ata_port_start,
  143. .port_stop = ata_port_stop,
  144. .host_stop = ata_host_stop,
  145. };
  146. static struct ata_port_info piix_port_info[] = {
  147. /* ich5_pata */
  148. {
  149. .sht = &piix_sht,
  150. .host_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST |
  151. PIIX_FLAG_CHECKINTR,
  152. .pio_mask = 0x1f, /* pio0-4 */
  153. #if 0
  154. .mwdma_mask = 0x06, /* mwdma1-2 */
  155. #else
  156. .mwdma_mask = 0x00, /* mwdma broken */
  157. #endif
  158. .udma_mask = 0x3f, /* udma0-5 */
  159. .port_ops = &piix_pata_ops,
  160. },
  161. /* ich5_sata */
  162. {
  163. .sht = &piix_sht,
  164. .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST |
  165. PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR,
  166. .pio_mask = 0x1f, /* pio0-4 */
  167. .mwdma_mask = 0x07, /* mwdma0-2 */
  168. .udma_mask = 0x7f, /* udma0-6 */
  169. .port_ops = &piix_sata_ops,
  170. },
  171. /* piix4_pata */
  172. {
  173. .sht = &piix_sht,
  174. .host_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  175. .pio_mask = 0x1f, /* pio0-4 */
  176. #if 0
  177. .mwdma_mask = 0x06, /* mwdma1-2 */
  178. #else
  179. .mwdma_mask = 0x00, /* mwdma broken */
  180. #endif
  181. .udma_mask = ATA_UDMA_MASK_40C,
  182. .port_ops = &piix_pata_ops,
  183. },
  184. /* ich6_sata */
  185. {
  186. .sht = &piix_sht,
  187. .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST |
  188. PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR |
  189. ATA_FLAG_SLAVE_POSS,
  190. .pio_mask = 0x1f, /* pio0-4 */
  191. .mwdma_mask = 0x07, /* mwdma0-2 */
  192. .udma_mask = 0x7f, /* udma0-6 */
  193. .port_ops = &piix_sata_ops,
  194. },
  195. /* ich6_sata_rm */
  196. {
  197. .sht = &piix_sht,
  198. .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST |
  199. PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR |
  200. ATA_FLAG_SLAVE_POSS | PIIX_FLAG_AHCI,
  201. .pio_mask = 0x1f, /* pio0-4 */
  202. .mwdma_mask = 0x07, /* mwdma0-2 */
  203. .udma_mask = 0x7f, /* udma0-6 */
  204. .port_ops = &piix_sata_ops,
  205. },
  206. /* ich7_sata */
  207. {
  208. .sht = &piix_sht,
  209. .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST |
  210. PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR |
  211. ATA_FLAG_SLAVE_POSS | PIIX_FLAG_AHCI,
  212. .pio_mask = 0x1f, /* pio0-4 */
  213. .mwdma_mask = 0x07, /* mwdma0-2 */
  214. .udma_mask = 0x7f, /* udma0-6 */
  215. .port_ops = &piix_sata_ops,
  216. },
  217. /* esb2_sata */
  218. {
  219. .sht = &piix_sht,
  220. .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST |
  221. PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR |
  222. ATA_FLAG_SLAVE_POSS | PIIX_FLAG_AHCI,
  223. .pio_mask = 0x1f, /* pio0-4 */
  224. .mwdma_mask = 0x07, /* mwdma0-2 */
  225. .udma_mask = 0x7f, /* udma0-6 */
  226. .port_ops = &piix_sata_ops,
  227. },
  228. };
  229. static struct pci_bits piix_enable_bits[] = {
  230. { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
  231. { 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */
  232. };
  233. MODULE_AUTHOR("Andre Hedrick, Alan Cox, Andrzej Krzysztofowicz, Jeff Garzik");
  234. MODULE_DESCRIPTION("SCSI low-level driver for Intel PIIX/ICH ATA controllers");
  235. MODULE_LICENSE("GPL");
  236. MODULE_DEVICE_TABLE(pci, piix_pci_tbl);
  237. MODULE_VERSION(DRV_VERSION);
  238. /**
  239. * piix_pata_cbl_detect - Probe host controller cable detect info
  240. * @ap: Port for which cable detect info is desired
  241. *
  242. * Read 80c cable indicator from ATA PCI device's PCI config
  243. * register. This register is normally set by firmware (BIOS).
  244. *
  245. * LOCKING:
  246. * None (inherited from caller).
  247. */
  248. static void piix_pata_cbl_detect(struct ata_port *ap)
  249. {
  250. struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
  251. u8 tmp, mask;
  252. /* no 80c support in host controller? */
  253. if ((ap->udma_mask & ~ATA_UDMA_MASK_40C) == 0)
  254. goto cbl40;
  255. /* check BIOS cable detect results */
  256. mask = ap->hard_port_no == 0 ? PIIX_80C_PRI : PIIX_80C_SEC;
  257. pci_read_config_byte(pdev, PIIX_IOCFG, &tmp);
  258. if ((tmp & mask) == 0)
  259. goto cbl40;
  260. ap->cbl = ATA_CBL_PATA80;
  261. return;
  262. cbl40:
  263. ap->cbl = ATA_CBL_PATA40;
  264. ap->udma_mask &= ATA_UDMA_MASK_40C;
  265. }
  266. /**
  267. * piix_pata_phy_reset - Probe specified port on PATA host controller
  268. * @ap: Port to probe
  269. *
  270. * Probe PATA phy.
  271. *
  272. * LOCKING:
  273. * None (inherited from caller).
  274. */
  275. static void piix_pata_phy_reset(struct ata_port *ap)
  276. {
  277. struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
  278. if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->hard_port_no])) {
  279. ata_port_disable(ap);
  280. printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
  281. return;
  282. }
  283. piix_pata_cbl_detect(ap);
  284. ata_port_probe(ap);
  285. ata_bus_reset(ap);
  286. }
  287. /**
  288. * piix_sata_probe - Probe PCI device for present SATA devices
  289. * @ap: Port associated with the PCI device we wish to probe
  290. *
  291. * Reads SATA PCI device's PCI config register Port Configuration
  292. * and Status (PCS) to determine port and device availability.
  293. *
  294. * LOCKING:
  295. * None (inherited from caller).
  296. *
  297. * RETURNS:
  298. * Non-zero if device detected, zero otherwise.
  299. */
  300. static int piix_sata_probe (struct ata_port *ap)
  301. {
  302. struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
  303. int combined = (ap->flags & ATA_FLAG_SLAVE_POSS);
  304. int orig_mask, mask, i;
  305. u8 pcs;
  306. mask = (PIIX_PORT_PRESENT << ap->hard_port_no) |
  307. (PIIX_PORT_ENABLED << ap->hard_port_no);
  308. pci_read_config_byte(pdev, ICH5_PCS, &pcs);
  309. orig_mask = (int) pcs & 0xff;
  310. /* TODO: this is vaguely wrong for ICH6 combined mode,
  311. * where only two of the four SATA ports are mapped
  312. * onto a single ATA channel. It is also vaguely inaccurate
  313. * for ICH5, which has only two ports. However, this is ok,
  314. * as further device presence detection code will handle
  315. * any false positives produced here.
  316. */
  317. for (i = 0; i < 4; i++) {
  318. mask = (PIIX_PORT_PRESENT << i) | (PIIX_PORT_ENABLED << i);
  319. if ((orig_mask & mask) == mask)
  320. if (combined || (i == ap->hard_port_no))
  321. return 1;
  322. }
  323. return 0;
  324. }
  325. /**
  326. * piix_sata_phy_reset - Probe specified port on SATA host controller
  327. * @ap: Port to probe
  328. *
  329. * Probe SATA phy.
  330. *
  331. * LOCKING:
  332. * None (inherited from caller).
  333. */
  334. static void piix_sata_phy_reset(struct ata_port *ap)
  335. {
  336. if (!piix_sata_probe(ap)) {
  337. ata_port_disable(ap);
  338. printk(KERN_INFO "ata%u: SATA port has no device.\n", ap->id);
  339. return;
  340. }
  341. ap->cbl = ATA_CBL_SATA;
  342. ata_port_probe(ap);
  343. ata_bus_reset(ap);
  344. }
  345. /**
  346. * piix_set_piomode - Initialize host controller PATA PIO timings
  347. * @ap: Port whose timings we are configuring
  348. * @adev: um
  349. * @pio: PIO mode, 0 - 4
  350. *
  351. * Set PIO mode for device, in host controller PCI config space.
  352. *
  353. * LOCKING:
  354. * None (inherited from caller).
  355. */
  356. static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev)
  357. {
  358. unsigned int pio = adev->pio_mode - XFER_PIO_0;
  359. struct pci_dev *dev = to_pci_dev(ap->host_set->dev);
  360. unsigned int is_slave = (adev->devno != 0);
  361. unsigned int master_port= ap->hard_port_no ? 0x42 : 0x40;
  362. unsigned int slave_port = 0x44;
  363. u16 master_data;
  364. u8 slave_data;
  365. static const /* ISP RTC */
  366. u8 timings[][2] = { { 0, 0 },
  367. { 0, 0 },
  368. { 1, 0 },
  369. { 2, 1 },
  370. { 2, 3 }, };
  371. pci_read_config_word(dev, master_port, &master_data);
  372. if (is_slave) {
  373. master_data |= 0x4000;
  374. /* enable PPE, IE and TIME */
  375. master_data |= 0x0070;
  376. pci_read_config_byte(dev, slave_port, &slave_data);
  377. slave_data &= (ap->hard_port_no ? 0x0f : 0xf0);
  378. slave_data |=
  379. (timings[pio][0] << 2) |
  380. (timings[pio][1] << (ap->hard_port_no ? 4 : 0));
  381. } else {
  382. master_data &= 0xccf8;
  383. /* enable PPE, IE and TIME */
  384. master_data |= 0x0007;
  385. master_data |=
  386. (timings[pio][0] << 12) |
  387. (timings[pio][1] << 8);
  388. }
  389. pci_write_config_word(dev, master_port, master_data);
  390. if (is_slave)
  391. pci_write_config_byte(dev, slave_port, slave_data);
  392. }
  393. /**
  394. * piix_set_dmamode - Initialize host controller PATA PIO timings
  395. * @ap: Port whose timings we are configuring
  396. * @adev: um
  397. * @udma: udma mode, 0 - 6
  398. *
  399. * Set UDMA mode for device, in host controller PCI config space.
  400. *
  401. * LOCKING:
  402. * None (inherited from caller).
  403. */
  404. static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  405. {
  406. unsigned int udma = adev->dma_mode; /* FIXME: MWDMA too */
  407. struct pci_dev *dev = to_pci_dev(ap->host_set->dev);
  408. u8 maslave = ap->hard_port_no ? 0x42 : 0x40;
  409. u8 speed = udma;
  410. unsigned int drive_dn = (ap->hard_port_no ? 2 : 0) + adev->devno;
  411. int a_speed = 3 << (drive_dn * 4);
  412. int u_flag = 1 << drive_dn;
  413. int v_flag = 0x01 << drive_dn;
  414. int w_flag = 0x10 << drive_dn;
  415. int u_speed = 0;
  416. int sitre;
  417. u16 reg4042, reg4a;
  418. u8 reg48, reg54, reg55;
  419. pci_read_config_word(dev, maslave, &reg4042);
  420. DPRINTK("reg4042 = 0x%04x\n", reg4042);
  421. sitre = (reg4042 & 0x4000) ? 1 : 0;
  422. pci_read_config_byte(dev, 0x48, &reg48);
  423. pci_read_config_word(dev, 0x4a, &reg4a);
  424. pci_read_config_byte(dev, 0x54, &reg54);
  425. pci_read_config_byte(dev, 0x55, &reg55);
  426. switch(speed) {
  427. case XFER_UDMA_4:
  428. case XFER_UDMA_2: u_speed = 2 << (drive_dn * 4); break;
  429. case XFER_UDMA_6:
  430. case XFER_UDMA_5:
  431. case XFER_UDMA_3:
  432. case XFER_UDMA_1: u_speed = 1 << (drive_dn * 4); break;
  433. case XFER_UDMA_0: u_speed = 0 << (drive_dn * 4); break;
  434. case XFER_MW_DMA_2:
  435. case XFER_MW_DMA_1: break;
  436. default:
  437. BUG();
  438. return;
  439. }
  440. if (speed >= XFER_UDMA_0) {
  441. if (!(reg48 & u_flag))
  442. pci_write_config_byte(dev, 0x48, reg48 | u_flag);
  443. if (speed == XFER_UDMA_5) {
  444. pci_write_config_byte(dev, 0x55, (u8) reg55|w_flag);
  445. } else {
  446. pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag);
  447. }
  448. if ((reg4a & a_speed) != u_speed)
  449. pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed);
  450. if (speed > XFER_UDMA_2) {
  451. if (!(reg54 & v_flag))
  452. pci_write_config_byte(dev, 0x54, reg54 | v_flag);
  453. } else
  454. pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
  455. } else {
  456. if (reg48 & u_flag)
  457. pci_write_config_byte(dev, 0x48, reg48 & ~u_flag);
  458. if (reg4a & a_speed)
  459. pci_write_config_word(dev, 0x4a, reg4a & ~a_speed);
  460. if (reg54 & v_flag)
  461. pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
  462. if (reg55 & w_flag)
  463. pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag);
  464. }
  465. }
  466. /* move to PCI layer, integrate w/ MSI stuff */
  467. static void pci_enable_intx(struct pci_dev *pdev)
  468. {
  469. u16 pci_command;
  470. pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
  471. if (pci_command & PCI_COMMAND_INTX_DISABLE) {
  472. pci_command &= ~PCI_COMMAND_INTX_DISABLE;
  473. pci_write_config_word(pdev, PCI_COMMAND, pci_command);
  474. }
  475. }
  476. #define AHCI_PCI_BAR 5
  477. #define AHCI_GLOBAL_CTL 0x04
  478. #define AHCI_ENABLE (1 << 31)
  479. static int piix_disable_ahci(struct pci_dev *pdev)
  480. {
  481. void *mmio;
  482. unsigned long addr;
  483. u32 tmp;
  484. int rc = 0;
  485. /* BUG: pci_enable_device has not yet been called. This
  486. * works because this device is usually set up by BIOS.
  487. */
  488. addr = pci_resource_start(pdev, AHCI_PCI_BAR);
  489. if (!addr || !pci_resource_len(pdev, AHCI_PCI_BAR))
  490. return 0;
  491. mmio = ioremap(addr, 64);
  492. if (!mmio)
  493. return -ENOMEM;
  494. tmp = readl(mmio + AHCI_GLOBAL_CTL);
  495. if (tmp & AHCI_ENABLE) {
  496. tmp &= ~AHCI_ENABLE;
  497. writel(tmp, mmio + AHCI_GLOBAL_CTL);
  498. tmp = readl(mmio + AHCI_GLOBAL_CTL);
  499. if (tmp & AHCI_ENABLE)
  500. rc = -EIO;
  501. }
  502. iounmap(mmio);
  503. return rc;
  504. }
  505. /**
  506. * piix_init_one - Register PIIX ATA PCI device with kernel services
  507. * @pdev: PCI device to register
  508. * @ent: Entry in piix_pci_tbl matching with @pdev
  509. *
  510. * Called from kernel PCI layer. We probe for combined mode (sigh),
  511. * and then hand over control to libata, for it to do the rest.
  512. *
  513. * LOCKING:
  514. * Inherited from PCI layer (may sleep).
  515. *
  516. * RETURNS:
  517. * Zero on success, or -ERRNO value.
  518. */
  519. static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  520. {
  521. static int printed_version;
  522. struct ata_port_info *port_info[2];
  523. unsigned int combined = 0, n_ports = 1;
  524. unsigned int pata_chan = 0, sata_chan = 0;
  525. if (!printed_version++)
  526. printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
  527. /* no hotplugging support (FIXME) */
  528. if (!in_module_init)
  529. return -ENODEV;
  530. port_info[0] = &piix_port_info[ent->driver_data];
  531. port_info[1] = NULL;
  532. if (port_info[0]->host_flags & PIIX_FLAG_AHCI) {
  533. int rc = piix_disable_ahci(pdev);
  534. if (rc)
  535. return rc;
  536. }
  537. if (port_info[0]->host_flags & PIIX_FLAG_COMBINED) {
  538. u8 tmp;
  539. pci_read_config_byte(pdev, ICH5_PMR, &tmp);
  540. if (tmp & PIIX_COMB) {
  541. combined = 1;
  542. if (tmp & PIIX_COMB_PATA_P0)
  543. sata_chan = 1;
  544. else
  545. pata_chan = 1;
  546. }
  547. }
  548. /* On ICH5, some BIOSen disable the interrupt using the
  549. * PCI_COMMAND_INTX_DISABLE bit added in PCI 2.3.
  550. * On ICH6, this bit has the same effect, but only when
  551. * MSI is disabled (and it is disabled, as we don't use
  552. * message-signalled interrupts currently).
  553. */
  554. if (port_info[0]->host_flags & PIIX_FLAG_CHECKINTR)
  555. pci_enable_intx(pdev);
  556. if (combined) {
  557. port_info[sata_chan] = &piix_port_info[ent->driver_data];
  558. port_info[sata_chan]->host_flags |= ATA_FLAG_SLAVE_POSS;
  559. port_info[pata_chan] = &piix_port_info[ich5_pata];
  560. n_ports++;
  561. printk(KERN_WARNING DRV_NAME ": combined mode detected\n");
  562. }
  563. return ata_pci_init_one(pdev, port_info, n_ports);
  564. }
  565. static int __init piix_init(void)
  566. {
  567. int rc;
  568. DPRINTK("pci_module_init\n");
  569. rc = pci_module_init(&piix_pci_driver);
  570. if (rc)
  571. return rc;
  572. in_module_init = 0;
  573. DPRINTK("done\n");
  574. return 0;
  575. }
  576. static void __exit piix_exit(void)
  577. {
  578. pci_unregister_driver(&piix_pci_driver);
  579. }
  580. module_init(piix_init);
  581. module_exit(piix_exit);