printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / southbridge / intel / i82801gx / i82801gx_pcie.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008-2009 coresystems GmbH
5  *
6  * 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.
10  *
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
26 static void pci_init(struct device *dev)
27 {
28         u16 reg16;
29         u32 reg32;
30
31         printk(BIOS_DEBUG, "Initializing ICH7 PCIe bridge.\n");
32
33         /* Enable Bus Master */
34         reg32 = pci_read_config32(dev, PCI_COMMAND);
35         reg32 |= PCI_COMMAND_MASTER;
36         pci_write_config32(dev, PCI_COMMAND, reg32);
37
38         /* Set Cache Line Size to 0x10 */
39         // This has no effect but the OS might expect it
40         pci_write_config8(dev, 0x0c, 0x10);
41
42         reg16 = pci_read_config16(dev, 0x3e);
43         reg16 &= ~(1 << 0); /* disable parity error response */
44         // reg16 &= ~(1 << 1); /* disable SERR */
45         reg16 |= (1 << 2); /* ISA enable */
46         pci_write_config16(dev, 0x3e, reg16);
47
48         /* 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);
52
53         /* 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);
57
58 #if CONFIG_MMCONF_SUPPORT
59         /* 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
78 #ifdef EVEN_MORE_DEBUG
79         reg32 = pci_read_config32(dev, 0x20);
80         printk(BIOS_SPEW, "    MBL    = 0x%08x\n", reg32);
81         reg32 = pci_read_config32(dev, 0x24);
82         printk(BIOS_SPEW, "    PMBL   = 0x%08x\n", reg32);
83         reg32 = pci_read_config32(dev, 0x28);
84         printk(BIOS_SPEW, "    PMBU32 = 0x%08x\n", reg32);
85         reg32 = pci_read_config32(dev, 0x2c);
86         printk(BIOS_SPEW, "    PMLU32 = 0x%08x\n", reg32);
87 #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);
97 }
98
99 static void pcie_set_subsystem(device_t dev, unsigned vendor, unsigned device)
100 {
101         /* 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         }
109 }
110
111 static struct pci_operations pci_ops = {
112         .set_subsystem = pcie_set_subsystem,
113 };
114
115 static 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
124 /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */
125 static const struct pci_driver i82801gx_pcie_port1 __pci_driver = {
126         .ops    = &device_ops,
127         .vendor = PCI_VENDOR_ID_INTEL,
128         .device = 0x27d0,
129 };
130
131 /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */
132 static const struct pci_driver i82801gx_pcie_port2 __pci_driver = {
133         .ops    = &device_ops,
134         .vendor = PCI_VENDOR_ID_INTEL,
135         .device = 0x27d2,
136 };
137
138 /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */
139 static const struct pci_driver i82801gx_pcie_port3 __pci_driver = {
140         .ops    = &device_ops,
141         .vendor = PCI_VENDOR_ID_INTEL,
142         .device = 0x27d4,
143 };
144
145 /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */
146 static const struct pci_driver i82801gx_pcie_port4 __pci_driver = {
147         .ops    = &device_ops,
148         .vendor = PCI_VENDOR_ID_INTEL,
149         .device = 0x27d6,
150 };
151
152 /* 82801GR/GDH/GHM (ICH7R/ICH7DH/ICH7-M DH) */
153 static const struct pci_driver i82801gx_pcie_port5 __pci_driver = {
154         .ops    = &device_ops,
155         .vendor = PCI_VENDOR_ID_INTEL,
156         .device = 0x27e0,
157 };
158
159 /* 82801GR/GDH/GHM (ICH7R/ICH7DH/ICH7-M DH) */
160 static const struct pci_driver i82801gx_pcie_port6 __pci_driver = {
161         .ops    = &device_ops,
162         .vendor = PCI_VENDOR_ID_INTEL,
163         .device = 0x27e2,
164 };