blob: 4cfc37ae6c94cedf84d8e4922d3ee8bfbe4d23ef [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Damien Zammit43a1f782015-08-19 15:16:59 +10003
4#include <stdint.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Martin Rothcbe38922016-01-05 19:40:41 -07006#include "iomap.h"
Julius Wernercd49cce2019-03-05 16:53:33 -08007#if CONFIG(SOUTHBRIDGE_INTEL_I82801GX)
Martin Rothcbe38922016-01-05 19:40:41 -07008#include <southbridge/intel/i82801gx/i82801gx.h> /* DEFAULT_PMBASE */
Arthur Heymans349e0852017-04-09 20:48:37 +02009#else
10#include <southbridge/intel/i82801jx/i82801jx.h> /* DEFAULT_PMBASE */
11#endif
Kyösti Mälkkicbf95712020-01-05 08:05:45 +020012#include <option.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100013#include "x4x.h"
Arthur Heymansef7e98a2016-12-30 21:07:18 +010014#include <console/console.h>
Arthur Heymansef7e98a2016-12-30 21:07:18 +010015#include <romstage_handoff.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100016
17void x4x_early_init(void)
18{
Antonello Dettori60a6e152016-09-03 10:45:33 +020019 const pci_devfn_t d0f0 = PCI_DEV(0, 0, 0);
Damien Zammit43a1f782015-08-19 15:16:59 +100020
21 /* Setup MCHBAR. */
22 pci_write_config32(d0f0, D0F0_MCHBAR_LO, (uintptr_t)DEFAULT_MCHBAR | 1);
23
24 /* Setup DMIBAR. */
25 pci_write_config32(d0f0, D0F0_DMIBAR_LO, (uintptr_t)DEFAULT_DMIBAR | 1);
26
27 /* Setup EPBAR. */
28 pci_write_config32(d0f0, D0F0_EPBAR_LO, DEFAULT_EPBAR | 1);
29
Damien Zammit43a1f782015-08-19 15:16:59 +100030 /* Setup HECIBAR */
Arthur Heymans70a1dda2017-03-09 01:58:24 +010031 pci_write_config32(PCI_DEV(0, 3, 0), 0x10, DEFAULT_HECIBAR);
Damien Zammit43a1f782015-08-19 15:16:59 +100032
33 /* Set C0000-FFFFF to access RAM on both reads and writes */
34 pci_write_config8(d0f0, D0F0_PAM(0), 0x30);
35 pci_write_config8(d0f0, D0F0_PAM(1), 0x33);
36 pci_write_config8(d0f0, D0F0_PAM(2), 0x33);
37 pci_write_config8(d0f0, D0F0_PAM(3), 0x33);
38 pci_write_config8(d0f0, D0F0_PAM(4), 0x33);
39 pci_write_config8(d0f0, D0F0_PAM(5), 0x33);
40 pci_write_config8(d0f0, D0F0_PAM(6), 0x33);
41
Arthur Heymans5e3cb722017-03-05 10:57:02 +010042 if (!(pci_read_config32(d0f0, D0F0_CAPID0 + 4) & (1 << (46 - 32)))) {
43 /* Enable internal GFX */
44 pci_write_config32(d0f0, D0F0_DEVEN, BOARD_DEVEN);
Arthur Heymanseff0c6a2016-06-18 21:52:30 +020045
Elyes HAOUAS2119d0b2020-02-16 10:01:33 +010046 /* Set preallocated IGD size from CMOS */
47 u8 gfxsize = 6; /* 6 for 64MiB, default if not set in CMOS */
Nico Hubercfd433b2017-05-12 17:10:58 +020048 get_option(&gfxsize, "gfx_uma_size");
49 if (gfxsize > 12)
Arthur Heymans5e3cb722017-03-05 10:57:02 +010050 gfxsize = 6;
Arthur Heymans16a70a42017-09-22 12:22:24 +020051 /* Need at least 4M for cbmem_top alignment */
52 else if (gfxsize < 1)
53 gfxsize = 1;
54 /* Set GTT size to 2+2M */
55 pci_write_config16(d0f0, D0F0_GGC, 0x0b00 | (gfxsize + 1) << 4);
Arthur Heymans5e3cb722017-03-05 10:57:02 +010056 } else { /* Does not feature internal graphics */
57 pci_write_config32(d0f0, D0F0_DEVEN, D0EN | D1EN | PEG1EN);
58 pci_write_config16(d0f0, D0F0_GGC, (1 << 1));
Arthur Heymanseff0c6a2016-06-18 21:52:30 +020059 }
Damien Zammit43a1f782015-08-19 15:16:59 +100060}
Arthur Heymansef7e98a2016-12-30 21:07:18 +010061
62static void init_egress(void)
63{
64 u32 reg32;
65
66 /* VC0: TC0 only */
67 EPBAR8(0x14) = 1;
68 EPBAR8(0x4) = 1;
69
70 switch (MCHBAR32(0xc00) & 0x7) {
71 case 0x0:
72 /* FSB 1066 */
73 EPBAR32(0x2c) = 0x0001a6db;
74 break;
75 case 0x2:
76 /* FSB 800 */
77 EPBAR32(0x2c) = 0x00014514;
78 break;
79 default:
80 case 0x4:
81 /* FSB 1333 */
82 EPBAR32(0x2c) = 0x00022861;
83 break;
84 }
85 EPBAR32(0x28) = 0x0a0a0a0a;
86 EPBAR8(0xc) = (EPBAR8(0xc) & ~0xe) | 2;
87 EPBAR32(0x1c) = (EPBAR32(0x1c) & ~0x7f0000) | 0x0a0000;
88 MCHBAR8(0x3c) = MCHBAR8(0x3c) | 0x7;
89
90 /* VC1: ID1, TC7 */
91 reg32 = (EPBAR32(0x20) & ~(7 << 24)) | (1 << 24);
92 reg32 = (reg32 & ~0xfe) | (1 << 7);
93 EPBAR32(0x20) = reg32;
94
95 /* Init VC1 port arbitration table */
96 EPBAR32(0x100) = 0x001000001;
97 EPBAR32(0x104) = 0x000040000;
98 EPBAR32(0x108) = 0x000001000;
99 EPBAR32(0x10c) = 0x000000040;
100 EPBAR32(0x110) = 0x001000001;
101 EPBAR32(0x114) = 0x000040000;
102 EPBAR32(0x118) = 0x000001000;
103 EPBAR32(0x11c) = 0x000000040;
104
105 /* Load table */
106 reg32 = EPBAR32(0x20) | (1 << 16);
107 EPBAR32(0x20) = reg32;
108 asm("nop");
109 EPBAR32(0x20) = reg32;
110
111 /* Wait for table load */
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100112 while ((EPBAR8(0x26) & (1 << 0)) != 0)
113 ;
Arthur Heymansef7e98a2016-12-30 21:07:18 +0100114
115 /* VC1: enable */
116 EPBAR32(0x20) |= 1 << 31;
117
118 /* Wait for VC1 */
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100119 while ((EPBAR8(0x26) & (1 << 1)) != 0)
120 ;
Arthur Heymansef7e98a2016-12-30 21:07:18 +0100121
122 printk(BIOS_DEBUG, "Done Egress Port\n");
123}
124
125static void init_dmi(void)
126{
127 u32 reg32;
Arthur Heymansef7e98a2016-12-30 21:07:18 +0100128
129 /* Assume IGD present */
130
131 /* Clear error status */
132 DMIBAR32(0x1c4) = 0xffffffff;
133 DMIBAR32(0x1d0) = 0xffffffff;
134
135 /* VC0: TC0 only */
136 DMIBAR8(DMIVC0RCTL) = 1;
137 DMIBAR8(0x4) = 1;
138
139 /* VC1: ID1, TC7 */
140 reg32 = (DMIBAR32(DMIVC1RCTL) & ~(7 << 24)) | (1 << 24);
141 reg32 = (reg32 & ~0xff) | 1 << 7;
142
143 /* VC1: enable */
144 reg32 |= 1 << 31;
145 reg32 = (reg32 & ~(0x7 << 17)) | (0x4 << 17);
146
147 DMIBAR32(DMIVC1RCTL) = reg32;
148
149 /* Set up VCs in southbridge RCBA */
150 RCBA8(0x3022) &= ~1;
151
152 reg32 = (0x5 << 28) | (1 << 6); /* PCIe x4 */
153 RCBA32(0x2020) = (RCBA32(0x2020) & ~((0xf << 28) | (0x7 << 6))) | reg32;
154
155 /* Assign VC1 id 1 */
156 RCBA32(0x20) = (RCBA32(0x20) & ~(0x7 << 24)) | (1 << 24);
157
158 /* Map TC7 to VC1 */
159 RCBA8(0x20) &= 1;
160 RCBA8(0x20) |= 1 << 7;
161
162 /* Map TC0 to VC0 */
163 RCBA8(0x14) &= 1;
164
165 /* Init DMI VC1 port arbitration table */
166 RCBA32(0x20) &= 0xfff1ffff;
167 RCBA32(0x20) |= 1 << 19;
168
169 RCBA32(0x30) = 0x0000000f;
170 RCBA32(0x34) = 0x000f0000;
171 RCBA32(0x38) = 0;
172 RCBA32(0x3c) = 0x000000f0;
173 RCBA32(0x40) = 0x0f000000;
174 RCBA32(0x44) = 0;
175 RCBA32(0x48) = 0x0000f000;
176 RCBA32(0x4c) = 0;
177 RCBA32(0x50) = 0x0000000f;
178 RCBA32(0x54) = 0x000f0000;
179 RCBA32(0x58) = 0;
180 RCBA32(0x5c) = 0x000000f0;
181 RCBA32(0x60) = 0x0f000000;
182 RCBA32(0x64) = 0;
183 RCBA32(0x68) = 0x0000f000;
184 RCBA32(0x6c) = 0;
185
186 RCBA32(0x20) |= 1 << 16;
187
188 /* Enable VC1 */
189 RCBA32(0x20) |= 1 << 31;
190
191 /* Wait for VC1 */
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100192 while ((RCBA8(0x26) & (1 << 1)) != 0)
193 ;
Arthur Heymansef7e98a2016-12-30 21:07:18 +0100194
195 /* Wait for table load */
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100196 while ((RCBA8(0x26) & (1 << 0)) != 0)
197 ;
Arthur Heymansef7e98a2016-12-30 21:07:18 +0100198
199 /* ASPM on DMI link */
200 RCBA16(0x1a8) &= ~0x3;
Elyes HAOUAS0c89c1c2019-05-20 18:39:27 +0200201 /* FIXME: Do we need to read RCBA16(0x1a8)? */
202 RCBA16(0x1a8);
Arthur Heymansef7e98a2016-12-30 21:07:18 +0100203 RCBA32(0x2010) = (RCBA32(0x2010) & ~(0x3 << 10)) | (1 << 10);
Elyes HAOUAS0c89c1c2019-05-20 18:39:27 +0200204 /* FIXME: Do we need to read RCBA32(0x2010)? */
205 RCBA32(0x2010);
Arthur Heymansef7e98a2016-12-30 21:07:18 +0100206
207 /* Set up VC1 max time */
208 RCBA32(0x1c) = (RCBA32(0x1c) & ~0x7f0000) | 0x120000;
209
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100210 while ((DMIBAR32(0x26) & (1 << 1)) != 0)
211 ;
Arthur Heymansef7e98a2016-12-30 21:07:18 +0100212 printk(BIOS_DEBUG, "Done DMI setup\n");
213
214 /* ASPM on DMI */
215 DMIBAR32(0x200) &= ~(0x3 << 26);
216 DMIBAR16(0x210) = (DMIBAR16(0x210) & ~(0xff7)) | 0x101;
217 DMIBAR32(0x88) &= ~0x3;
218 DMIBAR32(0x88) |= 0x3;
Elyes HAOUAS0c89c1c2019-05-20 18:39:27 +0200219 /* FIXME: Do we need to read RCBA16(0x88)? */
220 DMIBAR16(0x88);
Arthur Heymansef7e98a2016-12-30 21:07:18 +0100221}
222
223static void x4x_prepare_resume(int s3resume)
224{
Arthur Heymansef7e98a2016-12-30 21:07:18 +0100225 romstage_handoff_init(s3resume);
226}
227
228void x4x_late_init(int s3resume)
229{
230 init_egress();
231 init_dmi();
232 x4x_prepare_resume(s3resume);
233}