1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <device/pci_ops.h>
5 #include <device/pci_def.h>
6 #include <console/console.h>
7 #include <southbridge/intel/i82801ix/i82801ix.h>
11 static void init_egress(void)
14 epbar_clrbits8(EPVC0RCTL
, ~1);
15 epbar_clrsetbits8(EPPVCCAP1
, 7, 1);
18 epbar_write32(EPVC1MTS
, 0x0a0a0a0a);
19 epbar_clrsetbits32(EPVC1RCAP
, 127 << 16, 0x0a << 16);
22 epbar_clrsetbits32(EPVC1RCTL
, 7 << 24, 1 << 24);
23 epbar_clrsetbits8(EPVC1RCTL
, ~1, 1 << 7);
25 /* VC1 ARB table: setup and enable */
26 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);
36 do {} while ((epbar_read8(EPVC1RSTS
) & 1) != 0);
39 epbar_setbits32(EPVC1RCTL
, 1 << 31);
41 do {} while ((epbar_read8(EPVC1RSTS
) & 2) != 0);
45 /* b2step: b2 stepping or higher */
46 static void init_dmi(int b2step
)
49 dmibar_clrbits8(DMIVC0RCTL
, ~1);
50 dmibar_clrsetbits8(DMIPVCCAP1
, 7, 1);
53 dmibar_clrsetbits32(DMIVC1RCTL
, 7 << 24, 1 << 24);
54 dmibar_clrsetbits8(DMIVC1RCTL
, ~1, 1 << 7);
57 dmibar_setbits32(DMIVC1RCTL
, 1 << 31);
59 do {} while ((dmibar_read8(DMIVC1RSTS
) & VC1NP
) != 0);
61 /* additional configuration. */
62 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);
70 dmibar_setbits32(0xfc, 1 << 11);
72 dmibar_clrbits32(0xfc, 1 << 11);
74 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);
82 /* lock down write-once registers
83 DMIBAR32(0x84) will be set in setup_aspm(). */
84 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);
92 static void init_pcie(const int peg_enabled
,
93 const int sdvo_enabled
,
96 const pci_devfn_t mch
= PCI_DEV(0, 0, 0);
97 const pci_devfn_t pciex
= PCI_DEV(0, 1, 0);
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");
104 pci_or_config8(mch
, D0F0_DEVEN
, 1 << 1);
106 pci_write_config8(pciex
, 0x224,
107 (pci_read_config8(pciex
, 0x224) & ~31) | (peg_x16
? 16 : 0) | 1);
109 pci_and_config16(pciex
, 0x224, ~(1 << 8));
111 /* FIXME: fill in: slot or fixed? -> devicetree */
114 pci_or_config16(pciex
, PEG_CAP
, 1 << 8);
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 */
123 const u32 tmp
= (peg_slot
<< 17) | (peg_power_exp
<< 15) | (peg_power_val
<< 7);
124 pci_write_config32(pciex
, SLOTCAP
, tmp
);
127 pci_or_config8(pciex
, PEGLC
, 7);
129 /* VC0: TC0 only, VC0 only */
130 pci_and_config8(pciex
, D1F0_VC0RCTL
, 1);
132 pci_and_config8(pciex
, D1F0_VCCAP
, ~7);
136 static void setup_aspm(const stepping_t stepping
, const int peg_enabled
)
139 const pci_devfn_t pciex
= PCI_DEV(0, 1, 0);
141 /* Prerequisites for ASPM: */
143 pci_or_config32(pciex
, 0x200, 3 << 13);
145 pci_and_config32(pciex
, 0x0f0, ~((1 << 27) | (1 << 26)));
147 pci_or_config32(pciex
, 0x0f0, 3 << 24);
149 pci_and_config32(pciex
, 0x0f4, ~(1 << 4));
151 pci_or_config32(pciex
, 0x0fc, 1 << 0);
153 pci_or_config32(pciex
, 0x0fc, 1 << 1);
155 pci_or_config32(pciex
, 0x0fc, 1 << 4);
157 pci_and_config32(pciex
, 0x0fc, ~(7 << 5));
159 /* Set L0s, L1 supported in LCTL? */
160 pci_or_config32(pciex
, 0x0b0, 3 << 0);
162 pci_or_config32(pciex
, 0x0f0, 3 << 24);
164 tmp32
= pci_read_config32(pciex
, 0x0f0);
165 if ((stepping
>= STEPPING_B0
) && (stepping
<= STEPPING_B1
))
167 else if (stepping
>= STEPPING_B2
)
169 pci_write_config32(pciex
, 0x0f0, tmp32
);
171 tmp32
= pci_read_config32(pciex
, 0x0fc);
172 if ((stepping
>= STEPPING_B0
) && (stepping
<= STEPPING_B1
))
174 else if (stepping
>= STEPPING_B2
)
176 pci_write_config32(pciex
, 0x0fc, tmp32
);
178 tmp32
= pci_read_config32(pciex
, 0x0fc);
179 if (stepping
>= STEPPING_B2
)
181 pci_write_config32(pciex
, 0x0fc, tmp32
);
183 tmp32
= pci_read_config32(pciex
, 0x0fc);
184 if (stepping
>= STEPPING_B1
)
186 pci_write_config32(pciex
, 0x0fc, tmp32
);
188 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);
193 if (stepping
>= STEPPING_B0
) {
194 dmibar_clrsetbits32(0x0e28 + 4, 0xf << (52 - 32), 0xd << (52 - 32));
195 dmibar_write32(0x0e2c, 0x88d07333);
198 pci_and_config32(pciex
, 0xa08, ~(1 << 15));
200 pci_or_config32(pciex
, 0xa84, 1 << 8);
202 pci_and_config32(pciex
, 0xb14, ~(1 << 17));
204 pci_or_config32(pciex
, 0xb00, 3 << 8);
206 pci_or_config32(pciex
, 0xb00, 7 << 3);
208 pci_and_config32(pciex
, 0xa84, ~(1 << 8));
210 pci_or_config32(pciex
, 0xa84, 1 << 8);
212 pci_update_config32(pciex
, 0xb04, ~(0x1f << 23), 0x0e << 23);
214 pci_or_config32(pciex
, 0xb04, 1 << 31);
216 pci_update_config32(pciex
, 0xb04, ~(0x03 << 29), 0x01 << 29);
219 /*\ Setup ASPM on DMI \*/
221 /* Exit latencies should be checked to be supported by
222 the endpoint (ICH), but ICH doesn't give any limits. */
224 if (LPC_IS_MOBILE(PCI_DEV(0, 0x1f, 0)))
225 dmibar_setbits8(DMILCTL
, 3 << 0); // enable ASPM L0s, L1 (write-once)
227 dmibar_setbits8(DMILCTL
, 1 << 0); // enable ASPM L0s (write-once)
229 dmibar_clrsetbits32(DMILCAP
, 63 << 12, 2 << 12 | 2 << 15);
230 dmibar_write8(0x208 + 3, 0);
231 dmibar_clrbits32(0x208, 3 << 20);
233 /*\ Setup ASPM on PEG \*/
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
238 * generic ASPM code do the rest? - Nico
240 /* TODO: Prepare PEG for ASPM. */
243 static void setup_rcrb(const int peg_enabled
)
245 /*\ RCRB setup: Egress Port \*/
247 /* Set component ID of MCH (1). */
248 epbar_write8(EPESD
+ 2, 1);
250 /* Link1: component ID 1, link valid. */
251 epbar_clrsetbits32(EPLE1D
, 0xffffff, 1 << 16 | 1 << 0);
252 epbar_write32(EPLE1A
, CONFIG_FIXED_DMIBAR_MMIO_BASE
);
255 /* Link2: link_valid. */
256 epbar_setbits8(EPLE2D
, 1 << 0); /* link valid */
258 /*\ RCRB setup: DMI Port \*/
260 /* Set component ID of MCH (1). */
261 dmibar_write8(DMIESD
+ 2, 1);
263 /* Link1: target port 0, component id 2 (ICH), link valid. */
264 dmibar_write32(DMILE1D
, 0 << 24 | 2 << 16 | 1 << 0);
265 dmibar_write32(DMILE1A
, CONFIG_FIXED_RCBA_MMIO_BASE
);
267 /* Link2: component ID 1 (MCH), link valid */
268 dmibar_clrsetbits32(DMILE2D
, 0xffffff, 1 << 16 | 1 << 0);
269 dmibar_write32(DMILE2A
, CONFIG_FIXED_MCHBAR_MMIO_BASE
);
272 void gm45_late_init(const stepping_t stepping
)
274 const pci_devfn_t mch
= PCI_DEV(0, 0, 0);
275 const int peg_enabled
= (pci_read_config8(mch
, D0F0_DEVEN
) >> 1) & 1;
276 const int sdvo_enabled
= mchbar_read16(0x40) >> 8 & 1;
277 const int peg_x16
= (peg_enabled
&& !sdvo_enabled
);
280 init_dmi(stepping
>= STEPPING_B2
);
281 init_pcie(peg_enabled
, sdvo_enabled
, peg_x16
);
283 setup_aspm(stepping
, peg_enabled
);
284 setup_rcrb(peg_enabled
);