blob: b66a8870636e2a237f25bcc244f7d384f5e78a06 [file] [log] [blame]
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer54309d62009-01-20 22:53:10 +00004 * Copyright (C) 2008-2009 coresystems GmbH
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00005 *
Stefan Reinauera8e11682009-03-11 14:54:18 +00006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000010 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <console/console.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
25
26static void pci_init(struct device *dev)
27{
28 u16 reg16;
29 u32 reg32;
30
31 printk_debug("Initializing ICH7 PCIe bridge.\n");
Stefan Reinauer109ab312009-08-12 16:08:05 +000032
Stefan Reinauera8e11682009-03-11 14:54:18 +000033 /* Enable Bus Master */
34 reg32 = pci_read_config32(dev, PCI_COMMAND);
35 reg32 |= PCI_COMMAND_MASTER;
36 pci_write_config32(dev, PCI_COMMAND, reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000037
Stefan Reinauera8e11682009-03-11 14:54:18 +000038 /* Set Cache Line Size to 0x10 */
39 // This has no effect but the OS might expect it
40 pci_write_config8(dev, 0x0c, 0x10);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000041
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000042 reg16 = pci_read_config16(dev, 0x3e);
Stefan Reinauera8e11682009-03-11 14:54:18 +000043 reg16 &= ~(1 << 0); /* disable parity error response */
44 // reg16 &= ~(1 << 1); /* disable SERR */
45 reg16 |= (1 << 2); /* ISA enable */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000046 pci_write_config16(dev, 0x3e, reg16);
47
Stefan Reinauera8e11682009-03-11 14:54:18 +000048 /* Enable IO xAPIC on this PCIe port */
49 reg32 = pci_read_config32(dev, 0xd8);
50 reg32 |= (1 << 7);
51 pci_write_config32(dev, 0xd8, reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000052
Stefan Reinauera8e11682009-03-11 14:54:18 +000053 /* Enable Backbone Clock Gating */
54 reg32 = pci_read_config32(dev, 0xe1);
55 reg32 |= (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0);
56 pci_write_config32(dev, 0xe1, reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000057
Stefan Reinauer08670622009-06-30 15:17:49 +000058#if CONFIG_MMCONF_SUPPORT
Stefan Reinauera8e11682009-03-11 14:54:18 +000059 /* Set VC0 transaction class */
60 reg32 = pci_mmio_read_config32(dev, 0x114);
61 reg32 &= 0xffffff00;
62 reg32 |= 1;
63 pci_mmio_write_config32(dev, 0x114, reg32);
64
65 /* Mask completion timeouts */
66 reg32 = pci_mmio_read_config32(dev, 0x148);
67 reg32 |= (1 << 14);
68 pci_mmio_write_config32(dev, 0x148, reg32);
69#else
70#error "MMIO needed for ICH7 PCIe"
71#endif
72 /* Enable common clock configuration */
73 // Are there cases when we don't want that?
74 reg16 = pci_read_config16(dev, 0x50);
75 reg16 |= (1 << 6);
76 pci_write_config16(dev, 0x50, reg16);
77
Stefan Reinauerde3206a2010-02-22 06:09:43 +000078#ifdef EVEN_MORE_DEBUG
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000079 reg32 = pci_read_config32(dev, 0x20);
Stefan Reinauer54309d62009-01-20 22:53:10 +000080 printk_spew(" MBL = 0x%08x\n", reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000081 reg32 = pci_read_config32(dev, 0x24);
Stefan Reinauer54309d62009-01-20 22:53:10 +000082 printk_spew(" PMBL = 0x%08x\n", reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000083 reg32 = pci_read_config32(dev, 0x28);
Stefan Reinauer54309d62009-01-20 22:53:10 +000084 printk_spew(" PMBU32 = 0x%08x\n", reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000085 reg32 = pci_read_config32(dev, 0x2c);
Stefan Reinauer54309d62009-01-20 22:53:10 +000086 printk_spew(" PMLU32 = 0x%08x\n", reg32);
Stefan Reinauera8e11682009-03-11 14:54:18 +000087#endif
88
89 /* Clear errors in status registers */
90 reg16 = pci_read_config16(dev, 0x06);
91 //reg16 |= 0xf900;
92 pci_write_config16(dev, 0x06, reg16);
93
94 reg16 = pci_read_config16(dev, 0x1e);
95 //reg16 |= 0xf900;
96 pci_write_config16(dev, 0x1e, reg16);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000097}
98
Stefan Reinauera8e11682009-03-11 14:54:18 +000099static void pcie_set_subsystem(device_t dev, unsigned vendor, unsigned device)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000100{
Stefan Reinauera8e11682009-03-11 14:54:18 +0000101 /* NOTE: This is not the default position! */
102 if (!vendor || !device) {
103 pci_write_config32(dev, 0x94,
104 pci_read_config32(dev, 0));
105 } else {
106 pci_write_config32(dev, 0x94,
107 ((device & 0xffff) << 16) | (vendor & 0xffff));
108 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000109}
110
111static struct pci_operations pci_ops = {
Stefan Reinauera8e11682009-03-11 14:54:18 +0000112 .set_subsystem = pcie_set_subsystem,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000113};
114
115static struct device_operations device_ops = {
116 .read_resources = pci_bus_read_resources,
117 .set_resources = pci_dev_set_resources,
118 .enable_resources = pci_bus_enable_resources,
119 .init = pci_init,
120 .scan_bus = pci_scan_bridge,
121 .ops_pci = &pci_ops,
122};
123
Uwe Hermannbddc6932008-10-29 13:51:31 +0000124/* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000125static const struct pci_driver i82801gx_pcie_port1 __pci_driver = {
126 .ops = &device_ops,
Uwe Hermannbddc6932008-10-29 13:51:31 +0000127 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000128 .device = 0x27d0,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000129};
130
Uwe Hermannbddc6932008-10-29 13:51:31 +0000131/* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000132static const struct pci_driver i82801gx_pcie_port2 __pci_driver = {
133 .ops = &device_ops,
Uwe Hermannbddc6932008-10-29 13:51:31 +0000134 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000135 .device = 0x27d2,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000136};
137
Uwe Hermannbddc6932008-10-29 13:51:31 +0000138/* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000139static const struct pci_driver i82801gx_pcie_port3 __pci_driver = {
140 .ops = &device_ops,
Uwe Hermannbddc6932008-10-29 13:51:31 +0000141 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000142 .device = 0x27d4,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000143};
144
Uwe Hermannbddc6932008-10-29 13:51:31 +0000145/* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000146static const struct pci_driver i82801gx_pcie_port4 __pci_driver = {
147 .ops = &device_ops,
Uwe Hermannbddc6932008-10-29 13:51:31 +0000148 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000149 .device = 0x27d6,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000150};
151
Uwe Hermannbddc6932008-10-29 13:51:31 +0000152/* 82801GR/GDH/GHM (ICH7R/ICH7DH/ICH7-M DH) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000153static const struct pci_driver i82801gx_pcie_port5 __pci_driver = {
154 .ops = &device_ops,
Uwe Hermannbddc6932008-10-29 13:51:31 +0000155 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000156 .device = 0x27e0,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000157};
158
Uwe Hermannbddc6932008-10-29 13:51:31 +0000159/* 82801GR/GDH/GHM (ICH7R/ICH7DH/ICH7-M DH) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000160static const struct pci_driver i82801gx_pcie_port6 __pci_driver = {
161 .ops = &device_ops,
Uwe Hermannbddc6932008-10-29 13:51:31 +0000162 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000163 .device = 0x27e2,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000164};