blob: 132b684f301eff93477b0b2a692d1819b1e5f80a [file] [log] [blame]
Patrick Georgie72a8a32012-11-06 11:05:09 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * 2012 secunet Security Networks AG
6 * (Written by Nico Huber <nico.huber@secunet.com> for secunet)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; version 2 of
11 * the License.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Patrick Georgie72a8a32012-11-06 11:05:09 +010017 */
18
19#include <stdlib.h>
20#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020021#include <device/pci_ops.h>
Patrick Georgie72a8a32012-11-06 11:05:09 +010022#include <device/device.h>
23#include <device/pci.h>
24#include <console/console.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030025#include "chip.h"
Patrick Georgie72a8a32012-11-06 11:05:09 +010026#include "i82801ix.h"
27
28typedef struct southbridge_intel_i82801ix_config config_t;
29
Elyes HAOUAS8aa50732018-05-13 13:34:58 +020030static void i82801ix_enable_device(struct device *dev)
Patrick Georgie72a8a32012-11-06 11:05:09 +010031{
32 u32 reg32;
33
34 /* Enable SERR */
35 reg32 = pci_read_config32(dev, PCI_COMMAND);
36 reg32 |= PCI_COMMAND_SERR;
37 pci_write_config32(dev, PCI_COMMAND, reg32);
38}
39
40static void i82801ix_early_settings(const config_t *const info)
41{
42 /* Program FERR# as processor break event indicator. */
Stefan Taunercea31ea2018-08-11 18:45:28 +020043 RCBA32(GCS) |= (1 << 6);
44 /* BIOS must program...
45 * NB: other CIRs are handled in i82801ix_dmi_setup(). */
46 RCBA32(RCBA_CIR8) = (RCBA32(RCBA_CIR8) & ~(0x3 << 0)) | (0x2 << 0);
47 RCBA32(RCBA_FD) |= (1 << 0);
48 RCBA32(RCBA_CIR9) = (RCBA32(RCBA_CIR9) & ~(0x3 << 26)) | (0x2 << 26);
49 RCBA32(RCBA_CIR7) = (RCBA32(RCBA_CIR7) & ~(0xf << 16)) | (0x5 << 16);
50 RCBA32(RCBA_CIR13) = (RCBA32(RCBA_CIR13) & ~(0xf << 16)) | (0x5 << 16);
Stefan Tauner97c80892018-08-15 08:06:13 +020051 /* RCBA32(RCBA_CIR5) |= (1 << 0); cf. Specification Update */
Stefan Taunercea31ea2018-08-11 18:45:28 +020052 RCBA32(RCBA_CIR10) |= (3 << 16);
Patrick Georgie72a8a32012-11-06 11:05:09 +010053}
54
55static void i82801ix_pcie_init(const config_t *const info)
56{
Elyes HAOUAS8aa50732018-05-13 13:34:58 +020057 struct device *pciePort[6];
Patrick Georgie72a8a32012-11-06 11:05:09 +010058 int i, slot_number = 1; /* Reserve slot number 0 for nb's PEG. */
59 u32 reg32;
60
61 /* PCIe - BIOS must program... */
62 for (i = 0; i < 6; ++i) {
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030063 pciePort[i] = pcidev_on_root(0x1c, i);
Patrick Georgie72a8a32012-11-06 11:05:09 +010064 if (!pciePort[i]) {
65 printk(BIOS_EMERG, "PCIe port 00:1c.%x", i);
66 die(" is not listed in devicetree.\n");
67 }
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030068 reg32 = pci_read_config32(pciePort[i], 0x300);
69 pci_write_config32(pciePort[i], 0x300, reg32 | (1 << 21));
70 pci_write_config8(pciePort[i], 0x324, 0x40);
Patrick Georgie72a8a32012-11-06 11:05:09 +010071 }
72
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030073 if (LPC_IS_MOBILE(pcidev_on_root(0x1f, 0))) {
Patrick Georgie72a8a32012-11-06 11:05:09 +010074 for (i = 0; i < 6; ++i) {
75 if (pciePort[i]->enabled) {
76 reg32 = pci_read_config32(pciePort[i], 0xe8);
77 reg32 |= 1;
78 pci_write_config32(pciePort[i], 0xe8, reg32);
79 }
80 }
81 }
82
83 for (i = 5; (i >= 0) && !pciePort[i]->enabled; --i) {
84 /* Only for the top disabled ports. */
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030085 reg32 = pci_read_config32(pciePort[i], 0x300);
Patrick Georgie72a8a32012-11-06 11:05:09 +010086 reg32 |= 0x3 << 16;
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030087 pci_write_config32(pciePort[i], 0x300, reg32);
Patrick Georgie72a8a32012-11-06 11:05:09 +010088 }
89
90 /* Set slot implemented, slot number and slot power limits. */
91 for (i = 0; i < 6; ++i) {
Elyes HAOUAS8aa50732018-05-13 13:34:58 +020092 struct device *const dev = pciePort[i];
Patrick Georgie72a8a32012-11-06 11:05:09 +010093 u32 xcap = pci_read_config32(dev, D28Fx_XCAP);
94 if (info->pcie_slot_implemented & (1 << i))
95 xcap |= PCI_EXP_FLAGS_SLOT;
96 else
97 xcap &= ~PCI_EXP_FLAGS_SLOT;
98 pci_write_config32(dev, D28Fx_XCAP, xcap);
99
100 if (info->pcie_slot_implemented & (1 << i)) {
101 u32 slcap = pci_read_config32(dev, D28Fx_SLCAP);
102 slcap &= ~(0x1fff << 19);
103 slcap |= (slot_number++ << 19);
104 slcap &= ~(0x0003 << 16);
105 slcap |= (info->pcie_power_limits[i].scale << 16);
106 slcap &= ~(0x00ff << 7);
107 slcap |= (info->pcie_power_limits[i].value << 7);
108 pci_write_config32(dev, D28Fx_SLCAP, slcap);
109 }
110 }
111
112 /* Lock R/WO ASPM support bits. */
113 for (i = 0; i < 6; ++i) {
114 reg32 = pci_read_config32(pciePort[i], 0x4c);
115 pci_write_config32(pciePort[i], 0x4c, reg32);
116 }
117}
118
119static void i82801ix_ehci_init(void)
120{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300121 struct device *const pciEHCI1 = pcidev_on_root(0x1d, 7);
Patrick Georgie72a8a32012-11-06 11:05:09 +0100122 if (!pciEHCI1)
123 die("EHCI controller (00:1d.7) not listed in devicetree.\n");
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300124 struct device *const pciEHCI2 = pcidev_on_root(0x1a, 7);
Patrick Georgie72a8a32012-11-06 11:05:09 +0100125 if (!pciEHCI2)
126 die("EHCI controller (00:1a.7) not listed in devicetree.\n");
127
128 u32 reg32;
129
130 /* TODO: Maybe we have to save and
131 restore these settings across S3. */
132 reg32 = pci_read_config32(pciEHCI1, 0xfc);
133 pci_write_config32(pciEHCI1, 0xfc, (reg32 & ~(3 << 2)) |
134 (1 << 29) | (1 << 17) | (2 << 2));
135 reg32 = pci_read_config32(pciEHCI2, 0xfc);
136 pci_write_config32(pciEHCI2, 0xfc, (reg32 & ~(3 << 2)) |
137 (1 << 29) | (1 << 17) | (2 << 2));
138}
139
Martin Rothff744bf2019-10-23 21:46:03 -0600140static int i82801ix_function_disabled(const unsigned int devfn)
Patrick Georgie72a8a32012-11-06 11:05:09 +0100141{
Kyösti Mälkkie7377552018-06-21 16:20:55 +0300142 struct device *const dev = pcidev_path_on_root(devfn);
Patrick Georgie72a8a32012-11-06 11:05:09 +0100143 if (!dev) {
144 printk(BIOS_EMERG,
145 "PCI device 00:%x.%x",
146 PCI_SLOT(devfn), PCI_FUNC(devfn));
147 die(" is not listed in devicetree.\n");
148 }
149 return !dev->enabled;
150}
151
152static void i82801ix_hide_functions(void)
153{
154 int i;
155 u32 reg32;
156
157 /* FIXME: This works pretty good if the devicetree is consistent. But
158 some functions have to be disabled in right order and/or have
159 other constraints. */
160
161 if (i82801ix_function_disabled(PCI_DEVFN(0x19, 0)))
162 RCBA32(RCBA_BUC) |= BUC_LAND;
163
164 reg32 = RCBA32(RCBA_FD);
165 struct {
166 int devfn;
167 u32 mask;
168 } functions[] = {
169 { PCI_DEVFN(0x1a, 0), FD_U4D }, /* UHCI #4 */
170 { PCI_DEVFN(0x1a, 1), FD_U5D }, /* UHCI #5 */
171 { PCI_DEVFN(0x1a, 2), FD_U6D }, /* UHCI #6 */
172 { PCI_DEVFN(0x1a, 7), FD_EHCI2D }, /* EHCI #2 */
173 { PCI_DEVFN(0x1b, 0), FD_HDAD }, /* HD Audio */
174 { PCI_DEVFN(0x1c, 0), FD_PE1D }, /* PCIe #1 */
175 { PCI_DEVFN(0x1c, 1), FD_PE2D }, /* PCIe #2 */
176 { PCI_DEVFN(0x1c, 2), FD_PE3D }, /* PCIe #3 */
177 { PCI_DEVFN(0x1c, 3), FD_PE4D }, /* PCIe #4 */
178 { PCI_DEVFN(0x1c, 4), FD_PE5D }, /* PCIe #5 */
179 { PCI_DEVFN(0x1c, 5), FD_PE6D }, /* PCIe #6 */
180 { PCI_DEVFN(0x1d, 0), FD_U1D }, /* UHCI #1 */
181 { PCI_DEVFN(0x1d, 1), FD_U2D }, /* UHCI #2 */
182 { PCI_DEVFN(0x1d, 2), FD_U3D }, /* UHCI #3 */
183 { PCI_DEVFN(0x1d, 7), FD_EHCI1D }, /* EHCI #1 */
184 { PCI_DEVFN(0x1f, 0), FD_LBD }, /* LPC */
185 { PCI_DEVFN(0x1f, 2), FD_SAD1 }, /* SATA #1 */
186 { PCI_DEVFN(0x1f, 3), FD_SD }, /* SMBus */
187 { PCI_DEVFN(0x1f, 5), FD_SAD2 }, /* SATA #2 */
188 { PCI_DEVFN(0x1f, 6), FD_TTD }, /* Thermal Throttle */
189 };
190 for (i = 0; i < ARRAY_SIZE(functions); ++i) {
191 if (i82801ix_function_disabled(functions[i].devfn))
192 reg32 |= functions[i].mask;
193 }
194 RCBA32(RCBA_FD) = reg32;
195 RCBA32(RCBA_FD) |= (1 << 0); /* BIOS must write this... */
196 RCBA32(RCBA_FDSW) |= (1 << 7); /* Lock function-disable? */
197
198 /* Hide PCIe root port PCI functions. RPFN is partially R/WO. */
199 reg32 = RCBA32(RCBA_RPFN);
200 for (i = 0; i < 6; ++i) {
201 if (i82801ix_function_disabled(PCI_DEVFN(0x1c, i)))
202 reg32 |= (1 << ((i * 4) + 3));
203 }
204 RCBA32(RCBA_RPFN) = reg32;
205
206 /* Lock R/WO UHCI controller #6 remapping. */
207 RCBA32(RCBA_MAP) = RCBA32(RCBA_MAP);
208}
209
210static void i82801ix_init(void *chip_info)
211{
212 const config_t *const info = (config_t *)chip_info;
213
214 printk(BIOS_DEBUG, "Initializing i82801ix southbridge...\n");
215
216 i82801ix_early_settings(info);
217
218 /* PCI Express setup. */
219 i82801ix_pcie_init(info);
220
221 /* EHCI configuration. */
222 i82801ix_ehci_init();
223
224 /* Now hide internal functions. We can't access them after this. */
225 i82801ix_hide_functions();
226
227 /* Reset watchdog timer. */
Julius Wernercd49cce2019-03-05 16:53:33 -0800228#if !CONFIG(HAVE_SMI_HANDLER)
Patrick Georgie72a8a32012-11-06 11:05:09 +0100229 outw(0x0008, DEFAULT_TCOBASE + 0x12); /* Set higher timer value. */
230#endif
231 outw(0x0000, DEFAULT_TCOBASE + 0x00); /* Update timer. */
Patrick Georgie72a8a32012-11-06 11:05:09 +0100232}
233
234struct chip_operations southbridge_intel_i82801ix_ops = {
235 CHIP_NAME("Intel ICH9/ICH9-M (82801Ix) Series Southbridge")
236 .enable_dev = i82801ix_enable_device,
237 .init = i82801ix_init,
238};