1 /* 2004.12 yhlu add dual core support */
2 /* 24 June 2005 Cleaned up dual core support Eric Biederman */
4 #include <console/console.h>
6 #include <cpu/x86/lapic.h>
7 #include <cpu/amd/dualcore.h>
8 #include <device/device.h>
9 #include <device/pci.h>
10 #include <pc80/mc146818rtc.h>
11 #include <smp/spinlock.h>
12 #include <cpu/x86/mtrr.h>
13 #include "../model_fxx/model_fxx_msr.h"
14 #include "../../../northbridge/amd/amdk8/cpu_rev.c"
16 static int first_time = 1;
17 static int disable_siblings = !CONFIG_LOGICAL_CPUS;
18 void amd_sibling_init(device_t cpu, struct node_core_id id)
21 unsigned siblings, max_siblings;
23 /* On the bootstrap processor see if I want sibling cpus enabled */
26 get_option(&disable_siblings, "dual_core");
29 siblings = cpuid_ecx(0x80000008) & 0xff;
30 printk_debug("%d Sibling Cores found\n", siblings);
32 /* For now assume all cpus have the same number of siblings */
33 max_siblings = siblings + 1;
35 /* Wishlist? make dual cores look like hyperthreading */
37 /* See if I am a sibling cpu */
38 if (disable_siblings && (id.coreid != 0)) {
43 /* On the primary cpu find the siblings */
44 for (i = 1; i <= siblings; i++) {
45 struct device_path cpu_path;
47 /* Build the cpu device path */
48 cpu_path.type = DEVICE_PATH_APIC;
49 cpu_path.u.apic.apic_id =
50 (0x10 + i*0x10 + id.nodeid);
51 new = alloc_dev(cpu->bus, &cpu_path);
55 /* Report what I have done */
56 printk_debug("CPU: %s %s\n",
57 dev_path(new), new->enabled?"enabled":"disabled");
62 struct node_core_id get_node_core_id(void)
64 struct node_core_id id;
66 /* Get the apicid at reset */
67 id.nodeid = (cpuid_ebx(1) >> 24) & 0xff;
69 /* Find out how many siblings we have */
70 siblings = cpuid_ecx(0x80000008) & 0xff;
75 while ((1 << bits) <= siblings)
78 msr = rdmsr(NB_CFG_MSR);
79 if ((msr.hi >> (54-32)) & 1) {
80 // when NB_CFG[54] is set, nodeid = ebx[27:25], coreid = ebx[24]
81 id.coreid = id.nodeid & ((1 << bits) - 1);
84 // when NB_CFG[54] is clear, nodeid = ebx[26:24], coreid = ebx[27]
85 id.coreid = id.nodeid >> 3;
89 if (!is_cpu_pre_e0()) {
99 static int get_max_siblings(int nodes)
105 //get max siblings from all the nodes
106 for(nodeid=0; nodeid<nodes; nodeid++){
108 dev = dev_find_slot(0, PCI_DEVFN(0x18+nodeid, 3));
109 j = (pci_read_config32(dev, 0xe8) >> 12) & 3;
118 static void enable_apic_ext_id(int nodes)
123 //enable APIC_EXIT_ID all the nodes
124 for(nodeid=0; nodeid<nodes; nodeid++){
126 dev = dev_find_slot(0, PCI_DEVFN(0x18+nodeid, 0));
127 val = pci_read_config32(dev, 0x68);
128 val |= (1<<17)|(1<<18);
129 pci_write_config32(dev, 0x68, val);
134 unsigned get_apicid_base(unsigned ioapic_num)
138 unsigned apicid_base;
141 int bsp_apic_id = lapicid(); // bsp apicid
143 int disable_siblings = !CONFIG_LOGICAL_CPUS;
146 get_option(&disable_siblings, "dual_core");
148 //get the nodes number
149 dev = dev_find_slot(0, PCI_DEVFN(0x18,0));
150 nodes = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1;
152 siblings = get_max_siblings(nodes);
154 if(bsp_apic_id > 0) { // io apic could start from 0
156 } else if(pci_read_config32(dev, 0x68) & ( (1<<17) | (1<<18)) ) { // enabled ext id but bsp = 0
157 if(!disable_siblings) { return siblings + 1; }
161 nb_cfg_54 = read_nb_cfg_54();
164 //it is for all e0 single core and nc_cfg_54 low is set, but in the auto.c stage we do not set that bit for it.
165 if(nb_cfg_54 && (!disable_siblings) && (siblings == 0)) {
166 //we need to check if e0 single core is there
168 for(i=0; i<nodes; i++) {
169 if(is_e0_later_in_bsp(i)) {
177 //contruct apicid_base
179 if((!disable_siblings) && (siblings>0) ) {
180 /* for 8 way dual core, we will used up apicid 16:16, actualy 16 is not allowed by current kernel
181 and the kernel will try to get one that is small than 16 to make io apic work.
182 I don't know when the kernel can support 256 apic id. (APIC_EXT_ID is enabled) */
184 //4:10 for two way 8:12 for four way 16:16 for eight way
185 //Use CONFIG_MAX_PHYSICAL_CPUS instead of nodes for better consistency?
186 apicid_base = nb_cfg_54 ? (siblings+1) * nodes : 8 * siblings + nodes;
193 if((apicid_base+ioapic_num-1)>0xf) {
194 // We need to enable APIC EXT ID
195 printk_info("if the IO APIC device doesn't support 256 apic id, \r\n you need to set ENABLE_APIC_EXT_ID in auto.c so you can spare 16 id for ioapic\r\n");
196 enable_apic_ext_id(nodes);