cb256c4d7dbda303876aa270ef6475cdddb748ef
[coreboot.git] / src / cpu / amd / quadcore / quadcore.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Advanced Micro Devices, Inc.
5  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <console/console.h>
21 #include <pc80/mc146818rtc_early.c>
22 #include <northbridge/amd/amdht/ht_wrapper.c>
23
24 #ifndef SET_NB_CFG_54
25         #define SET_NB_CFG_54 1
26 #endif
27
28 #include "cpu/amd/quadcore/quadcore_id.c"
29
30 static u32 get_core_num_in_bsp(u32 nodeid)
31 {
32         u32 dword;
33         dword = pci_read_config32(NODE_PCI(nodeid, 3), 0xe8);
34         dword >>= 12;
35         /* Bit 15 is CmpCap[2] since Revision D. */
36         if ((cpuid_ecx(0x80000008) & 0xff) > 3)
37             dword = ((dword & 8) >> 1) | (dword & 3);
38         else
39             dword &= 3;
40         return dword;
41 }
42
43 #if SET_NB_CFG_54 == 1
44 static u8 set_apicid_cpuid_lo(void)
45 {
46         // set the NB_CFG[54]=1; why the OS will be happy with that ???
47         msr_t msr;
48         msr = rdmsr(NB_CFG_MSR);
49         msr.hi |= (1<<(54-32)); // InitApicIdCpuIdLo
50         wrmsr(NB_CFG_MSR, msr);
51
52         return 1;
53 }
54 #else
55
56 static void set_apicid_cpuid_lo(void) { }
57
58 #endif
59
60
61 static void real_start_other_core(u32 nodeid, u32 cores)
62 {
63         u32 dword, i;
64
65         printk(BIOS_DEBUG, "Start other core - nodeid: %02x  cores: %02x\n", nodeid, cores);
66
67         /* set PCI_DEV(0, 0x18+nodeid, 3), 0x44 bit 27 to redirect all MC4
68            accesses and error logging to core0 */
69         dword = pci_read_config32(NODE_PCI(nodeid, 3), 0x44);
70         dword |= 1 << 27;       // NbMcaToMstCpuEn bit
71         pci_write_config32(NODE_PCI(nodeid, 3), 0x44, dword);
72         // set PCI_DEV(0, 0x18+nodeid, 0), 0x68 bit 5 to start core1
73         dword = pci_read_config32(NODE_PCI(nodeid, 0), 0x68);
74         dword |= 1 << 5;
75         pci_write_config32(NODE_PCI(nodeid, 0), 0x68, dword);
76
77         if(cores > 1) {
78                 dword = pci_read_config32(NODE_PCI(nodeid, 0), 0x168);
79                 for (i = 0; i < cores - 1; i++) {
80                         dword |= 1 << i;
81                 }
82                 pci_write_config32(NODE_PCI(nodeid, 0), 0x168, dword);
83         }
84 }
85
86 //it is running on core0 of node0
87 static void start_other_cores(void)
88 {
89         u32 nodes;
90         u32 nodeid;
91
92         // disable multi_core
93         if (read_option(CMOS_VSTART_multi_core, CMOS_VLEN_multi_core, 0) != 0)  {
94                 printk(BIOS_DEBUG, "Skip additional core init\n");
95                 return;
96         }
97
98         nodes = get_nodes();
99
100         for (nodeid = 0; nodeid < nodes; nodeid++) {
101                 u32 cores = get_core_num_in_bsp(nodeid);
102                 printk(BIOS_DEBUG, "init node: %02x  cores: %02x \n", nodeid, cores);
103                 if (cores > 0) {
104                         real_start_other_core(nodeid, cores);
105                 }
106         }
107
108 }