blob: 59a49929d7b2967a3d1447d8d27270fd60635b08 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgi2efc8802012-11-06 11:03:53 +01002
3#include <stdint.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01005#include <device/pci_def.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01006#include <console/console.h>
Angel Pons2f30e8c2020-09-16 13:29:21 +02007#include <southbridge/intel/i82801ix/i82801ix.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01008
9#include "gm45.h"
10
11static void init_egress(void)
12{
13 /* VC0: TC0 only */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010014 epbar_clrbits8(EPVC0RCTL, ~1);
15 epbar_clrsetbits8(EPPVCCAP1, 7, 1);
Patrick Georgi2efc8802012-11-06 11:03:53 +010016
17 /* VC1: isoch */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010018 epbar_write32(EPVC1MTS, 0x0a0a0a0a);
19 epbar_clrsetbits32(EPVC1RCAP, 127 << 16, 0x0a << 16);
Patrick Georgi2efc8802012-11-06 11:03:53 +010020
21 /* VC1: ID1, TC7 */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010022 epbar_clrsetbits32(EPVC1RCTL, 7 << 24, 1 << 24);
23 epbar_clrsetbits8(EPVC1RCTL, ~1, 1 << 7);
Patrick Georgi2efc8802012-11-06 11:03:53 +010024
25 /* VC1 ARB table: setup and enable */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010026 epbar_write32(EP_PORTARB(0), 0x55555555);
27 epbar_write32(EP_PORTARB(1), 0x55555555);
28 epbar_write32(EP_PORTARB(2), 0x55555555);
29 epbar_write32(EP_PORTARB(3), 0x55555555);
30 epbar_write32(EP_PORTARB(4), 0x55555555);
31 epbar_write32(EP_PORTARB(5), 0x55555555);
32 epbar_write32(EP_PORTARB(6), 0x55555555);
33 epbar_write32(EP_PORTARB(7), 0x00005555);
34 epbar_setbits32(EPVC1RCTL, 1 << 16);
Patrick Georgi2efc8802012-11-06 11:03:53 +010035
Angel Pons63976872022-11-02 01:04:24 +010036 do {} while ((epbar_read8(EPVC1RSTS) & 1) != 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010037
38 /* VC1: enable */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010039 epbar_setbits32(EPVC1RCTL, 1 << 31);
Patrick Georgi2efc8802012-11-06 11:03:53 +010040
Angel Pons63976872022-11-02 01:04:24 +010041 do {} while ((epbar_read8(EPVC1RSTS) & 2) != 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010042}
43
44/* MCH side */
45/* b2step: b2 stepping or higher */
46static void init_dmi(int b2step)
47{
48 /* VC0: TC0 only */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010049 dmibar_clrbits8(DMIVC0RCTL, ~1);
50 dmibar_clrsetbits8(DMIPVCCAP1, 7, 1);
Patrick Georgi2efc8802012-11-06 11:03:53 +010051
52 /* VC1: ID1, TC7 */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010053 dmibar_clrsetbits32(DMIVC1RCTL, 7 << 24, 1 << 24);
54 dmibar_clrsetbits8(DMIVC1RCTL, ~1, 1 << 7);
Patrick Georgi2efc8802012-11-06 11:03:53 +010055
56 /* VC1: enable */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010057 dmibar_setbits32(DMIVC1RCTL, 1 << 31);
Patrick Georgi2efc8802012-11-06 11:03:53 +010058
Angel Pons63976872022-11-02 01:04:24 +010059 do {} while ((dmibar_read8(DMIVC1RSTS) & VC1NP) != 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010060
61 /* additional configuration. */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010062 dmibar_setbits32(0x200, 3 << 13);
63 dmibar_clrbits32(0x200, 1 << 21);
64 dmibar_clrsetbits32(0x200, 3 << 26, 2 << 26);
65 dmibar_write32(0x2c, 0x86000040);
66 dmibar_setbits32(0xfc, 1 << 0);
67 dmibar_setbits32(0xfc, 1 << 1);
68 dmibar_setbits32(0xfc, 1 << 4);
Patrick Georgi2efc8802012-11-06 11:03:53 +010069 if (!b2step) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010070 dmibar_setbits32(0xfc, 1 << 11);
Patrick Georgi2efc8802012-11-06 11:03:53 +010071 } else {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010072 dmibar_clrbits32(0xfc, 1 << 11);
Patrick Georgi2efc8802012-11-06 11:03:53 +010073 }
Angel Pons3f1f8ef2021-03-27 13:52:43 +010074 dmibar_clrbits32(0x204, 3 << 10);
75 dmibar_clrbits32(0xf4, 1 << 4);
76 dmibar_setbits32(0xf0, 3 << 24);
77 dmibar_write32(0xf04, 0x07050880);
78 dmibar_write32(0xf44, 0x07050880);
79 dmibar_write32(0xf84, 0x07050880);
80 dmibar_write32(0xfc4, 0x07050880);
Patrick Georgi2efc8802012-11-06 11:03:53 +010081
82 /* lock down write-once registers
83 DMIBAR32(0x84) will be set in setup_aspm(). */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010084 dmibar_setbits32(0x308, 0);
85 dmibar_setbits32(0x314, 0);
86 dmibar_setbits32(0x324, 0);
87 dmibar_setbits32(0x328, 0);
88 dmibar_setbits32(0x334, 0);
89 dmibar_setbits32(0x338, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010090}
91
92static void init_pcie(const int peg_enabled,
93 const int sdvo_enabled,
94 const int peg_x16)
95{
Furquan Shaikh25f75b22016-08-29 22:51:41 -070096 const pci_devfn_t mch = PCI_DEV(0, 0, 0);
97 const pci_devfn_t pciex = PCI_DEV(0, 1, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010098
99 printk(BIOS_DEBUG, "PEG x%d %s, SDVO %s\n", peg_x16?16:1,
100 peg_enabled?"enabled":"disabled",
101 sdvo_enabled?"enabled":"disabled");
102
103 if (peg_enabled) {
Angel Ponsb0535832020-06-08 11:46:58 +0200104 pci_or_config8(mch, D0F0_DEVEN, 1 << 1);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100105
Angel Ponsb0535832020-06-08 11:46:58 +0200106 pci_write_config8(pciex, 0x224,
107 (pci_read_config8(pciex, 0x224) & ~31) | (peg_x16 ? 16 : 0) | 1);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100108
Angel Ponsb0535832020-06-08 11:46:58 +0200109 pci_and_config16(pciex, 0x224, ~(1 << 8));
Patrick Georgi2efc8802012-11-06 11:03:53 +0100110
111 /* FIXME: fill in: slot or fixed? -> devicetree */
112 int peg_is_slot = 0;
113 if (peg_is_slot) {
Angel Ponsb0535832020-06-08 11:46:58 +0200114 pci_or_config16(pciex, PEG_CAP, 1 << 8);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100115 }
116
117 /* FIXME: fill in: slot number, slot power -> devicetree */
118 /* Use slot number 0 by now, slots on sb count from 1. */
119 int peg_slot = 0; /* unique within chassis */
120 /* peg_power := val * 10^-exp */
121 int peg_power_val = 75;
122 int peg_power_exp = 0; /* 0..3 */
Angel Ponsb0535832020-06-08 11:46:58 +0200123 const u32 tmp = (peg_slot << 17) | (peg_power_exp << 15) | (peg_power_val << 7);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100124 pci_write_config32(pciex, SLOTCAP, tmp);
125
126 /* GPEs */
Angel Ponsb0535832020-06-08 11:46:58 +0200127 pci_or_config8(pciex, PEGLC, 7);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100128
129 /* VC0: TC0 only, VC0 only */
Angel Ponsb0535832020-06-08 11:46:58 +0200130 pci_and_config8(pciex, D1F0_VC0RCTL, 1);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100131
Angel Ponsb0535832020-06-08 11:46:58 +0200132 pci_and_config8(pciex, D1F0_VCCAP, ~7);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100133 }
134}
135
136static void setup_aspm(const stepping_t stepping, const int peg_enabled)
137{
138 u32 tmp32;
Furquan Shaikh25f75b22016-08-29 22:51:41 -0700139 const pci_devfn_t pciex = PCI_DEV(0, 1, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100140
141 /* Prerequisites for ASPM: */
142 if (peg_enabled) {
Angel Ponsb0535832020-06-08 11:46:58 +0200143 pci_or_config32(pciex, 0x200, 3 << 13);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100144
Angel Ponsb0535832020-06-08 11:46:58 +0200145 pci_and_config32(pciex, 0x0f0, ~((1 << 27) | (1 << 26)));
Patrick Georgi2efc8802012-11-06 11:03:53 +0100146
Angel Ponsb0535832020-06-08 11:46:58 +0200147 pci_or_config32(pciex, 0x0f0, 3 << 24);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100148
Angel Ponsb0535832020-06-08 11:46:58 +0200149 pci_and_config32(pciex, 0x0f4, ~(1 << 4));
Patrick Georgi2efc8802012-11-06 11:03:53 +0100150
Angel Ponsb0535832020-06-08 11:46:58 +0200151 pci_or_config32(pciex, 0x0fc, 1 << 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100152
Angel Ponsb0535832020-06-08 11:46:58 +0200153 pci_or_config32(pciex, 0x0fc, 1 << 1);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100154
Angel Ponsb0535832020-06-08 11:46:58 +0200155 pci_or_config32(pciex, 0x0fc, 1 << 4);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100156
Angel Ponsb0535832020-06-08 11:46:58 +0200157 pci_and_config32(pciex, 0x0fc, ~(7 << 5));
Patrick Georgi2efc8802012-11-06 11:03:53 +0100158
159 /* Set L0s, L1 supported in LCTL? */
Angel Ponsb0535832020-06-08 11:46:58 +0200160 pci_or_config32(pciex, 0x0b0, 3 << 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100161
Angel Ponsb0535832020-06-08 11:46:58 +0200162 pci_or_config32(pciex, 0x0f0, 3 << 24);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100163
164 tmp32 = pci_read_config32(pciex, 0x0f0);
165 if ((stepping >= STEPPING_B0) && (stepping <= STEPPING_B1))
166 tmp32 |= (1 << 31);
167 else if (stepping >= STEPPING_B2)
168 tmp32 &= ~(1 << 31);
169 pci_write_config32(pciex, 0x0f0, tmp32);
170
171 tmp32 = pci_read_config32(pciex, 0x0fc);
172 if ((stepping >= STEPPING_B0) && (stepping <= STEPPING_B1))
173 tmp32 |= (1 << 10);
174 else if (stepping >= STEPPING_B2)
175 tmp32 &= ~(1 << 10);
176 pci_write_config32(pciex, 0x0fc, tmp32);
177
178 tmp32 = pci_read_config32(pciex, 0x0fc);
179 if (stepping >= STEPPING_B2)
180 tmp32 |= (1 << 14);
181 pci_write_config32(pciex, 0x0fc, tmp32);
182
183 tmp32 = pci_read_config32(pciex, 0x0fc);
184 if (stepping >= STEPPING_B1)
185 tmp32 &= ~(1 << 13);
186 pci_write_config32(pciex, 0x0fc, tmp32);
187 }
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100188 dmibar_setbits8(0x0e1c, 1 << 0);
189 dmibar_setbits16(0x0f00, 3 << 8);
190 dmibar_setbits16(0x0f00, 7 << 3);
191 dmibar_clrbits32(0x0f14, 1 << 17);
192 dmibar_clrbits16(0x0e1c, 1 << 8);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100193 if (stepping >= STEPPING_B0) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100194 dmibar_clrsetbits32(0x0e28 + 4, 0xf << (52 - 32), 0xd << (52 - 32));
195 dmibar_write32(0x0e2c, 0x88d07333);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100196 }
197 if (peg_enabled) {
Angel Ponsb0535832020-06-08 11:46:58 +0200198 pci_and_config32(pciex, 0xa08, ~(1 << 15));
Patrick Georgi2efc8802012-11-06 11:03:53 +0100199
Angel Ponsb0535832020-06-08 11:46:58 +0200200 pci_or_config32(pciex, 0xa84, 1 << 8);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100201
Angel Ponsb0535832020-06-08 11:46:58 +0200202 pci_and_config32(pciex, 0xb14, ~(1 << 17));
Patrick Georgi2efc8802012-11-06 11:03:53 +0100203
Angel Ponsb0535832020-06-08 11:46:58 +0200204 pci_or_config32(pciex, 0xb00, 3 << 8);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100205
Angel Ponsb0535832020-06-08 11:46:58 +0200206 pci_or_config32(pciex, 0xb00, 7 << 3);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100207
Angel Ponsb0535832020-06-08 11:46:58 +0200208 pci_and_config32(pciex, 0xa84, ~(1 << 8));
Patrick Georgi2efc8802012-11-06 11:03:53 +0100209
Angel Ponsb0535832020-06-08 11:46:58 +0200210 pci_or_config32(pciex, 0xa84, 1 << 8);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100211
Angel Ponsb0535832020-06-08 11:46:58 +0200212 pci_update_config32(pciex, 0xb04, ~(0x1f << 23), 0x0e << 23);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100213
Angel Ponsb0535832020-06-08 11:46:58 +0200214 pci_or_config32(pciex, 0xb04, 1 << 31);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100215
Angel Ponsb0535832020-06-08 11:46:58 +0200216 pci_update_config32(pciex, 0xb04, ~(0x03 << 29), 0x01 << 29);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100217 }
218
Patrick Georgi2efc8802012-11-06 11:03:53 +0100219 /*\ Setup ASPM on DMI \*/
220
221 /* Exit latencies should be checked to be supported by
222 the endpoint (ICH), but ICH doesn't give any limits. */
223
224 if (LPC_IS_MOBILE(PCI_DEV(0, 0x1f, 0)))
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100225 dmibar_setbits8(DMILCTL, 3 << 0); // enable ASPM L0s, L1 (write-once)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100226 else
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100227 dmibar_setbits8(DMILCTL, 1 << 0); // enable ASPM L0s (write-once)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100228 /* timing */
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100229 dmibar_clrsetbits32(DMILCAP, 63 << 12, 2 << 12 | 2 << 15);
230 dmibar_write8(0x208 + 3, 0);
231 dmibar_clrbits32(0x208, 3 << 20);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100232
Patrick Georgi2efc8802012-11-06 11:03:53 +0100233 /*\ Setup ASPM on PEG \*/
234 /*
235 * Maybe we just have to advertise ASPM through LCAP[11:10]
236 * (LCAP[17:15] == 010b is the default, will be locked, as it's R/WO),
237 * set 0x208[31:24,23:22] to zero, 0x224[24:21] = 1 and let the
Martin Roth0cd338e2016-07-29 14:07:30 -0600238 * generic ASPM code do the rest? - Nico
Patrick Georgi2efc8802012-11-06 11:03:53 +0100239 */
240 /* TODO: Prepare PEG for ASPM. */
241}
242
243static void setup_rcrb(const int peg_enabled)
244{
245 /*\ RCRB setup: Egress Port \*/
246
247 /* Set component ID of MCH (1). */
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100248 epbar_write8(EPESD + 2, 1);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100249
250 /* Link1: component ID 1, link valid. */
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100251 epbar_clrsetbits32(EPLE1D, 0xffffff, 1 << 16 | 1 << 0);
252 epbar_write32(EPLE1A, CONFIG_FIXED_DMIBAR_MMIO_BASE);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100253
254 if (peg_enabled)
255 /* Link2: link_valid. */
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100256 epbar_setbits8(EPLE2D, 1 << 0); /* link valid */
Patrick Georgi2efc8802012-11-06 11:03:53 +0100257
Patrick Georgi2efc8802012-11-06 11:03:53 +0100258 /*\ RCRB setup: DMI Port \*/
259
260 /* Set component ID of MCH (1). */
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100261 dmibar_write8(DMIESD + 2, 1);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100262
263 /* Link1: target port 0, component id 2 (ICH), link valid. */
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100264 dmibar_write32(DMILE1D, 0 << 24 | 2 << 16 | 1 << 0);
265 dmibar_write32(DMILE1A, CONFIG_FIXED_RCBA_MMIO_BASE);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100266
267 /* Link2: component ID 1 (MCH), link valid */
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100268 dmibar_clrsetbits32(DMILE2D, 0xffffff, 1 << 16 | 1 << 0);
269 dmibar_write32(DMILE2A, CONFIG_FIXED_MCHBAR_MMIO_BASE);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100270}
271
272void gm45_late_init(const stepping_t stepping)
273{
Furquan Shaikh25f75b22016-08-29 22:51:41 -0700274 const pci_devfn_t mch = PCI_DEV(0, 0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100275 const int peg_enabled = (pci_read_config8(mch, D0F0_DEVEN) >> 1) & 1;
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100276 const int sdvo_enabled = mchbar_read16(0x40) >> 8 & 1;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100277 const int peg_x16 = (peg_enabled && !sdvo_enabled);
278
279 init_egress();
280 init_dmi(stepping >= STEPPING_B2);
281 init_pcie(peg_enabled, sdvo_enabled, peg_x16);
282
283 setup_aspm(stepping, peg_enabled);
284 setup_rcrb(peg_enabled);
285}