2 * This file is part of the coreboot project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #define NBHTIU_INDEX 0xA8
22 #define NBMISC_INDEX 0x60
23 #define NBMC_INDEX 0xE8
25 static u32 nb_read_index(device_t dev, u32 index_reg, u32 index)
27 pci_write_config32(dev, index_reg, index);
28 return pci_read_config32(dev, index_reg + 0x4);
31 static void nb_write_index(device_t dev, u32 index_reg, u32 index, u32 data)
33 pci_write_config32(dev, index_reg, index /* | 0x80 */ );
34 pci_write_config32(dev, index_reg + 0x4, data);
37 static u32 nbmisc_read_index(device_t nb_dev, u32 index)
39 return nb_read_index((nb_dev), NBMISC_INDEX, (index));
42 static void nbmisc_write_index(device_t nb_dev, u32 index, u32 data)
44 nb_write_index((nb_dev), NBMISC_INDEX, ((index) | 0x80), (data));
47 static u32 htiu_read_index(device_t nb_dev, u32 index)
49 return nb_read_index((nb_dev), NBHTIU_INDEX, (index));
52 static void htiu_write_index(device_t nb_dev, u32 index, u32 data)
54 nb_write_index((nb_dev), NBHTIU_INDEX, ((index) | 0x100), (data));
57 static u32 nbmc_read_index(device_t nb_dev, u32 index)
59 return nb_read_index((nb_dev), NBMC_INDEX, (index));
62 static void nbmc_write_index(device_t nb_dev, u32 index, u32 data)
64 nb_write_index((nb_dev), NBMC_INDEX, ((index) | 1 << 9), (data));
67 static void set_htiu_enable_bits(device_t nb_dev, u32 reg_pos, u32 mask,
71 reg = reg_old = htiu_read_index(nb_dev, reg_pos);
75 htiu_write_index(nb_dev, reg_pos, reg);
79 static void set_nbmisc_enable_bits(device_t nb_dev, u32 reg_pos, u32 mask,
83 reg = reg_old = nbmisc_read_index(nb_dev, reg_pos);
87 nbmisc_write_index(nb_dev, reg_pos, reg);
91 static void set_nbcfg_enable_bits(device_t nb_dev, u32 reg_pos, u32 mask,
95 reg = reg_old = pci_read_config32(nb_dev, reg_pos);
99 pci_write_config32(nb_dev, reg_pos, reg);
103 static void set_nbcfg_enable_bits_8(device_t nb_dev, u32 reg_pos, u8 mask,
107 reg = reg_old = pci_read_config8(nb_dev, reg_pos);
110 if (reg != reg_old) {
111 pci_write_config8(nb_dev, reg_pos, reg);
115 static void set_nbmc_enable_bits(device_t nb_dev, u32 reg_pos, u32 mask,
119 reg = reg_old = nbmc_read_index(nb_dev, reg_pos);
122 if (reg != reg_old) {
123 nbmc_write_index(nb_dev, reg_pos, reg);
128 * Compliant with CIM_33's ATINB_PrepareInit
130 static void get_cpu_rev()
132 u32 eax, ebx, ecx, edx;
133 __asm__ volatile ("cpuid":"=a" (eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
135 printk_info("get_cpu_rev EAX=0x%x.\n", eax);
137 printk_info("CPU Rev is K8_Cx.\n");
138 else if (eax <= 0x10fff)
139 printk_info("CPU Rev is K8_Dx.\n");
140 else if (eax <= 0x20fff)
141 printk_info("CPU Rev is K8_Ex.\n");
142 else if (eax <= 0x40fff)
143 printk_info("CPU Rev is K8_Fx.\n");
144 else if (eax == 0x60fb1 || eax == 0x60f81) /*These two IDS are exception, they are G1. */
145 printk_info("CPU Rev is K8_G1.\n");
146 else if (eax <= 0X60FF0)
147 printk_info("CPU Rev is K8_G0.\n");
148 else if (eax <= 0x100000)
149 printk_info("CPU Rev is K8_G1.\n");
151 printk_info("CPU Rev is K8_10.\n");
154 static u8 get_nb_rev(device_t nb_dev)
157 reg = pci_read_config32(nb_dev, 0x00);
158 if (0x7911 == (reg >> 16))
160 reg = pci_read_config8(nb_dev, 0x89); /* copy from CIM, can't find in doc */
161 if (reg & 0x2) /* check bit1 */
163 if (reg & 0x1) /* check bit0 */
169 /*****************************************
170 * Compliant with CIM_33's ATINB_HTInit
171 * Init HT link speed/width for rs690 -- k8 link
172 *****************************************/
173 static void rs690_htinit()
176 * About HT, it has been done in enumerate_ht_chain().
182 k8_f0 = PCI_DEV(0, 0x18, 0);
183 /************************
184 * get k8's ht freq, in k8's function 0, offset 0x88
185 * bit11-8, specifics the maximum operation frequency of the link's transmitter clock.
186 * The link frequency field (Frq) is cleared by cold reset. SW can write a nonzero
187 * value to this reg, and that value takes effect on the next warm reset or
188 * LDTSTOP_L disconnect sequence.
195 ************************/
196 reg = pci_read_config32(k8_f0, 0x88);
197 k8_ht_freq = (reg & 0xf00) >> 8;
198 printk_info("rs690_ht_init k8_ht_freq=%x.\n", k8_ht_freq);
201 /*******************************************************
202 * Optimize k8 with UMA.
203 * See BKDG_NPT_0F guide for details.
204 * The processor node is addressed by its Node ID on the HT link and can be
205 * accessed with a device number in the PCI configuration space on Bus0.
206 * The Node ID 0 is mapped to Device 24 (0x18), the Node ID 1 is mapped
207 * to Device 25, and so on.
208 * The processor implements configuration registers in PCI configuration
209 * space using the following four headers
210 * Function0: HT technology configuration
211 * Function1: Address map configuration
212 * Function2: DRAM and HT technology Trace mode configuration
213 * Function3: Miscellaneous configuration
214 *******************************************************/
215 static void k8_optimization()
217 device_t k8_f0, k8_f2, k8_f3;
220 printk_info("k8_optimization()\n");
221 k8_f0 = PCI_DEV(0, 0x18, 0);
222 k8_f2 = PCI_DEV(0, 0x18, 2);
223 k8_f3 = PCI_DEV(0, 0x18, 3);
225 pci_write_config32(k8_f0, 0x90, 0x01700178); /* CIM NPT_Optimization */
226 set_nbcfg_enable_bits(k8_f0, 0x68, 1 << 28, 0 << 28);
227 set_nbcfg_enable_bits(k8_f0, 0x68, 1 << 26 | 1 << 27,
229 set_nbcfg_enable_bits(k8_f0, 0x68, 1 << 11, 1 << 11);
230 set_nbcfg_enable_bits(k8_f0, 0x84, 1 << 11 | 1 << 13 | 1 << 15, 1 << 11 | 1 << 13 | 1 << 15); /* TODO */
232 pci_write_config32(k8_f3, 0x70, 0x51320111); /* CIM NPT_Optimization */
233 pci_write_config32(k8_f3, 0x74, 0x50304021);
234 pci_write_config32(k8_f3, 0x78, 0x08002A00);
235 if (pci_read_config32(k8_f3, 0xE8) & 0x3<<12)
236 pci_write_config32(k8_f3, 0x7C, 0x0000211B); /* dual core */
238 pci_write_config32(k8_f3, 0x7C, 0x0000211C); /* single core */
239 set_nbcfg_enable_bits_8(k8_f3, 0xDC, 0xFF, 0x25);
241 set_nbcfg_enable_bits(k8_f2, 0xA0, 1 << 5, 1 << 5);
242 set_nbcfg_enable_bits(k8_f2, 0x94, 0xF << 24, 7 << 24);
243 set_nbcfg_enable_bits(k8_f2, 0x90, 1 << 10, 1 << 10);
244 set_nbcfg_enable_bits(k8_f2, 0xA0, 3 << 2, 3 << 2);
245 set_nbcfg_enable_bits(k8_f2, 0xA0, 1 << 5, 1 << 5);
247 msr = rdmsr(0xC001001F);
250 wrmsr(0xC001001F, msr);
253 /*****************************************
254 * Compliant with CIM_33's ATINB_PCICFG_POR_TABLE
255 *****************************************/
256 static void rs690_por_pcicfg_init(device_t nb_dev)
258 /* enable PCI Memory Access */
259 set_nbcfg_enable_bits_8(nb_dev, 0x04, (u8)(~0xFD), 0x02);
260 /* Set RCRB Enable */
261 set_nbcfg_enable_bits_8(nb_dev, 0x84, (u8)(~0xFF), 0x1);
262 /* allow decode of 640k-1MB */
263 set_nbcfg_enable_bits_8(nb_dev, 0x84, (u8)(~0xEF), 0x10);
264 /* Enable PM2_CNTL(BAR2) IO mapped cfg write access to be broadcast to both NB and SB */
265 set_nbcfg_enable_bits_8(nb_dev, 0x84, (u8)(~0xFF), 0x4);
266 /* Power Management Register Enable */
267 set_nbcfg_enable_bits_8(nb_dev, 0x84, (u8)(~0xFF), 0x80);
269 /* Reg4Ch[1]=1 (APIC_ENABLE) force cpu request with address 0xFECx_xxxx to south-bridge
270 * Reg4Ch[6]=1 (BMMsgEn) enable BM_Set message generation
272 set_nbcfg_enable_bits_8(nb_dev, 0x4C, (u8)(~0x00), 0x42 | 1);
274 /* Reg4Ch[16]=1 (WakeC2En) enable Wake_from_C2 message generation.
275 * Reg4Ch[18]=1 (P4IntEnable) Enable north-bridge to accept MSI with address 0xFEEx_xxxx from south-bridge */
276 set_nbcfg_enable_bits_8(nb_dev, 0x4E, (u8)(~0xFF), 0x05);
277 /* Reg94h[4:0] = 0x0 P drive strength offset 0
278 * Reg94h[6:5] = 0x2 P drive strength additive adjust */
279 set_nbcfg_enable_bits_8(nb_dev, 0x94, (u8)(~0x80), 0x40);
281 /* Reg94h[20:16] = 0x0 N drive strength offset 0
282 * Reg94h[22:21] = 0x2 N drive strength additive adjust */
283 set_nbcfg_enable_bits_8(nb_dev, 0x96, (u8)(~0x80), 0x40);
285 /* Reg80h[4:0] = 0x0 Termination offset
286 * Reg80h[6:5] = 0x2 Termination additive adjust */
287 set_nbcfg_enable_bits_8(nb_dev, 0x80, (u8)(~0x80), 0x40);
289 /* Reg80h[14] = 0x1 Enable receiver termination control */
290 set_nbcfg_enable_bits_8(nb_dev, 0x81, (u8)(~0xFF), 0x40);
292 /* Reg94h[15] = 0x1 Enables HT transmitter advanced features to be turned on
293 * Reg94h[14] = 0x1 Enable drive strength control */
294 set_nbcfg_enable_bits_8(nb_dev, 0x95, (u8)(~0x3F), 0xC4);
296 /* Reg94h[31:29] = 0x7 Enables HT transmitter de-emphasis */
297 set_nbcfg_enable_bits_8(nb_dev, 0x97, (u8)(~0x1F), 0xE0);
299 /*Reg8Ch[10:9] = 0x3 Enables Gfx Debug BAR,
300 * force this BAR as mem type in rs690_gfx.c */
301 set_nbcfg_enable_bits_8(nb_dev, 0x8D, (u8)(~0xFF), 0x03);
305 /*****************************************
306 * Compliant with CIM_33's ATINB_MCIndex_POR_TABLE
307 *****************************************/
308 static void rs690_por_mc_index_init(device_t nb_dev)
310 set_nbmc_enable_bits(nb_dev, 0x7A, ~0xFFFFFF80, 0x0000005F);
311 set_nbmc_enable_bits(nb_dev, 0xD8, ~0x00000000, 0x00600060);
312 set_nbmc_enable_bits(nb_dev, 0xD9, ~0x00000000, 0x00600060);
313 set_nbmc_enable_bits(nb_dev, 0xE0, ~0x00000000, 0x00000000);
314 set_nbmc_enable_bits(nb_dev, 0xE1, ~0x00000000, 0x00000000);
315 set_nbmc_enable_bits(nb_dev, 0xE8, ~0x00000000, 0x003E003E);
316 set_nbmc_enable_bits(nb_dev, 0xE9, ~0x00000000, 0x003E003E);
319 /*****************************************
320 * Compliant with CIM_33's ATINB_MISCIND_POR_TABLE
321 * Compliant with CIM_33's MISC_INIT_TBL
322 *****************************************/
323 static void rs690_por_misc_index_init(device_t nb_dev)
325 /* NB_MISC_IND_WR_EN + IOC_PCIE_CNTL
326 * Block non-snoop DMA request if PMArbDis is set.
328 set_nbmisc_enable_bits(nb_dev, 0x0B, ~0xFFFF0000, 0x00000180);
329 set_nbmisc_enable_bits(nb_dev, 0x01, ~0xFFFFFFFF, 0x00000040);
331 /* NBCFG (NBMISCIND 0x0): NB_CNTL -
332 * HIDE_NB_AGP_CAP ([0], default=1)HIDE
333 * HIDE_P2P_AGP_CAP ([1], default=1)HIDE
334 * HIDE_NB_GART_BAR ([2], default=1)HIDE
335 * AGPMODE30 ([4], default=0)DISABLE
336 * AGP30ENCHANCED ([5], default=0)DISABLE
337 * HIDE_AGP_CAP ([8], default=1)ENABLE */
338 set_nbmisc_enable_bits(nb_dev, 0x00, ~0xFFFF0000, 0x00000506); /* set bit 10 for MSI */
340 /* NBMISCIND:0x6A[16]= 1 SB link can get a full swing
341 * set_nbmisc_enable_bits(nb_dev, 0x6A, 0ffffffffh, 000010000);
342 * NBMISCIND:0x6A[17]=1 Set CMGOOD_OVERRIDE. */
343 set_nbmisc_enable_bits(nb_dev, 0x6A, ~0xffffffff, 0x00020000);
345 /* NBMISIND:0x40 Bit[8]=1 and Bit[10]=1 following bits are required to set in order to allow LVDS or PWM features to work. */
346 set_nbmisc_enable_bits(nb_dev, 0x40, ~0xffffffff, 0x00000500);
348 /* NBMISIND:0xC Bit[13]=1 Enable GSM mode for C1e or C3 with pop-up. */
349 set_nbmisc_enable_bits(nb_dev, 0x0C, ~0xffffffff, 0x00002000);
351 /* Set NBMISIND:0x1F[3] to map NB F2 interrupt pin to INTB# */
352 set_nbmisc_enable_bits(nb_dev, 0x1F, ~0xffffffff, 0x00000008);
354 /* Compliant with CIM_33's MISC_INIT_TBL, except Hide NB_BAR3_PCIE
355 * Enable access to DEV8
356 * Enable setPower message for all ports
358 set_nbmisc_enable_bits(nb_dev, 0x00, 1 << 6, 1 << 6);
359 set_nbmisc_enable_bits(nb_dev, 0x0b, 1 << 20, 1 << 20);
360 set_nbmisc_enable_bits(nb_dev, 0x51, 1 << 20, 1 << 20);
361 set_nbmisc_enable_bits(nb_dev, 0x53, 1 << 20, 1 << 20);
362 set_nbmisc_enable_bits(nb_dev, 0x55, 1 << 20, 1 << 20);
363 set_nbmisc_enable_bits(nb_dev, 0x57, 1 << 20, 1 << 20);
364 set_nbmisc_enable_bits(nb_dev, 0x59, 1 << 20, 1 << 20);
365 set_nbmisc_enable_bits(nb_dev, 0x5B, 1 << 20, 1 << 20);
367 set_nbmisc_enable_bits(nb_dev, 0x00, 1 << 7, 1 << 7);
368 set_nbmisc_enable_bits(nb_dev, 0x07, 0x000000f0, 0x30);
369 /* Disable bus-master trigger event from SB and Enable set_slot_power message to SB */
370 set_nbmisc_enable_bits(nb_dev, 0x0B, 0xffffffff, 0x500180);
373 /*****************************************
374 * Compliant with CIM_33's ATINB_HTIUNBIND_POR_TABLE
375 *****************************************/
376 static void rs690_por_htiu_index_init(device_t nb_dev)
379 * Enables GSM mode for C1e or C3 with pop-up
380 * Prevents AllowLdtStop from being asserted during HT link recovery
381 * Allows FID cycles to be serviced faster. Needed for RS690 A12. No harm in RS690 A11 */
382 set_htiu_enable_bits(nb_dev, 0x05, ~0xffffffff, 0x0BC);
384 * Enables writes to pass in-progress reads
385 * Enables streaming of CPU writes
386 * Enables extended write buffer for CPU writes
387 * Enables additional response buffers
388 * Enables special reads to pass writes
389 * Enables decoding of C1e/C3 and FID cycles
390 * Enables HTIU-display handshake bypass.
391 * Enables tagging fix */
392 set_htiu_enable_bits(nb_dev, 0x06, ~0xFFFFFFFE, 0x4203A202);
394 /* Enables byte-write optimization for IOC requests
395 * Disables delaying STPCLK de-assert during FID sequence. Needed when enhanced UMA arbitration is used.
396 * Disables upstream system-management delay */
397 set_htiu_enable_bits(nb_dev, 0x07, ~0xFFFFFFF9, 0x001);
399 /* HTIUNBIND 0x16 [1] = 0x1 Enable crc decoding fix */
400 set_htiu_enable_bits(nb_dev, 0x16, ~0xFFFFFFFF, 0x2);
403 /*****************************************
404 * Compliant with CIM_33's ATINB_POR_INIT_JMPDI
405 * Configure RS690 registers to power-on default RPR.
406 * POR: Power On Reset
407 * RPR: Register Programming Requirements
408 *****************************************/
409 static void rs690_por_init(device_t nb_dev)
411 printk_info("rs690_por_init\n");
412 /* ATINB_PCICFG_POR_TABLE, initialize the values for rs690 PCI Config registers */
413 rs690_por_pcicfg_init(nb_dev);
415 /* ATINB_MCIND_POR_TABLE */
416 rs690_por_mc_index_init(nb_dev);
418 /* ATINB_MISCIND_POR_TABLE */
419 rs690_por_misc_index_init(nb_dev);
421 /* ATINB_HTIUNBIND_POR_TABLE */
422 rs690_por_htiu_index_init(nb_dev);
424 /* ATINB_CLKCFG_PORT_TABLE */
425 /* rs690 A11 SB Link full swing? */
428 /* enable CFG access to Dev8, which is the SB P2P Bridge */
429 static void enable_rs690_dev8()
431 set_nbmisc_enable_bits(PCI_DEV(0, 0, 0), 0x00, 1 << 6, 1 << 6);
437 * Compliant with CIM_33's AtiNBInitEarlyPost (AtiInitNBBeforePCIInit).
439 static void rs690_before_pci_init()
444 * The calling sequence is same as CIM.
446 static void rs690_early_setup()
448 device_t nb_dev = PCI_DEV(0, 0, 0);
449 printk_info("rs690_early_setup()\n");
451 /*ATINB_PrepareInit */
453 switch (get_nb_rev(nb_dev)) { /* PCIEMiscInit */
455 printk_info("NB Revision is A11.\n");
458 printk_info("NB Revision is A12.\n");
461 printk_info("NB Revision is A21.\n");
467 rs690_por_init(nb_dev);