1 /* 2004.12 yhlu add dual core support */
3 #include <console/console.h>
5 #include <cpu/x86/lapic.h>
6 #include <cpu/amd/dualcore.h>
7 #include <device/device.h>
8 #include <device/pci.h>
9 #include <pc80/mc146818rtc.h>
10 #include <smp/spinlock.h>
11 #include <cpu/x86/mtrr.h>
12 #include <cpu/amd/model_fxx_msr.h>
13 #include <cpu/amd/model_fxx_rev.h>
14 #include <cpu/amd/amdk8_sysconf.h>
16 static int first_time = 1;
17 static int disable_siblings = !CONFIG_LOGICAL_CPUS;
19 #include "dualcore_id.c"
21 static int get_max_siblings(int nodes)
27 //get max siblings from all the nodes
28 for(nodeid=0; nodeid<nodes; nodeid++){
30 dev = dev_find_slot(0, PCI_DEVFN(0x18+nodeid, 3));
31 j = (pci_read_config32(dev, 0xe8) >> 12) & 3;
40 static void enable_apic_ext_id(int nodes)
45 //enable APIC_EXIT_ID all the nodes
46 for(nodeid=0; nodeid<nodes; nodeid++){
48 dev = dev_find_slot(0, PCI_DEVFN(0x18+nodeid, 0));
49 val = pci_read_config32(dev, 0x68);
50 val |= (1<<17)|(1<<18);
51 pci_write_config32(dev, 0x68, val);
56 unsigned get_apicid_base(unsigned ioapic_num)
63 int bsp_apic_id = lapicid(); // bsp apicid
65 int disable_siblings = !CONFIG_LOGICAL_CPUS;
68 get_option(&disable_siblings, "dual_core");
70 //get the nodes number
71 dev = dev_find_slot(0, PCI_DEVFN(0x18,0));
72 nodes = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1;
74 siblings = get_max_siblings(nodes);
76 if(bsp_apic_id > 0) { // io apic could start from 0
78 } else if(pci_read_config32(dev, 0x68) & ( (1<<17) | (1<<18)) ) { // enabled ext id but bsp = 0
82 nb_cfg_54 = read_nb_cfg_54();
85 //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.
86 if(nb_cfg_54 && (!disable_siblings) && (siblings == 0)) {
87 //we need to check if e0 single core is there
89 for(i=0; i<nodes; i++) {
90 if(is_e0_later_in_bsp(i)) {
98 //contruct apicid_base
100 if((!disable_siblings) && (siblings>0) ) {
101 /* for 8 way dual core, we will used up apicid 16:16, actualy 16 is not allowed by current kernel
102 and the kernel will try to get one that is small than 16 to make io apic work.
103 I don't know when the kernel can support 256 apic id. (APIC_EXT_ID is enabled) */
105 //4:10 for two way 8:12 for four way 16:16 for eight way
106 //Use CONFIG_MAX_PHYSICAL_CPUS instead of nodes for better consistency?
107 apicid_base = nb_cfg_54 ? (siblings+1) * nodes : 8 * siblings + nodes;
114 if((apicid_base+ioapic_num-1)>0xf) {
115 // We need to enable APIC EXT ID
116 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");
117 enable_apic_ext_id(nodes);
123 void amd_sibling_init(device_t cpu)
125 unsigned i, siblings;
126 struct cpuid_result result;
128 struct node_core_id id;
130 /* On the bootstrap processor see if I want sibling cpus enabled */
133 get_option(&disable_siblings, "dual_core");
135 result = cpuid(0x80000008);
136 /* See how many sibling cpus we have */
137 /* Is dualcore supported */
138 siblings = (result.ecx & 0xff);
144 printk_debug("CPU: %u %d siblings\n",
145 cpu->path.apic.apic_id,
149 nb_cfg_54 = read_nb_cfg_54();
151 id = get_node_core_id(nb_cfg_54); // pre e0 nb_cfg_54 can not be set
153 /* See if I am a sibling cpu */
154 //if ((cpu->path.apic.apic_id>>(nb_cfg_54?0:3)) & siblings ) { // siblings = 1, 3, 7, 15,....
155 //if ( ( (cpu->path.apic.apic_id>>(nb_cfg_54?0:3)) % (siblings+1) ) != 0 ) {
157 if (disable_siblings) {
164 /* I am the primary cpu start up my siblings */
166 for(i = 1; i <= siblings; i++) {
167 struct device_path cpu_path;
169 /* Build the cpu device path */
170 cpu_path.type = DEVICE_PATH_APIC;
171 cpu_path.apic.apic_id = cpu->path.apic.apic_id + i * (nb_cfg_54?1:8);
173 // need some special processing, because may the bsp is not lifted, but the core1 is lifted
174 //defined in northbridge.c
175 if(sysconf.enabled_apic_ext_id && (!sysconf.lift_bsp_apicid)) {
176 cpu->path.apic.apic_id += sysconf.apicid_offset;
182 /* See if I can find the cpu */
183 new = find_dev_path(cpu->bus, &cpu_path);
184 /* Allocate the new cpu device structure */
186 new = alloc_dev(cpu->bus, &cpu_path);
188 new->initialized = 0;
191 new->path.apic.node_id = cpu->path.apic.node_id;
192 new->path.apic.core_id = i;
195 printk_debug("CPU: %u has sibling %u\n",
196 cpu->path.apic.apic_id,
197 new->path.apic.apic_id);
200 if(new->enabled && !new->initialized)