2 * This file is part of the LinuxBIOS project.
4 * Copyright (C) 2007 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 #include <console/console.h>
23 #include <cpu/x86/lapic.h>
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <pc80/mc146818rtc.h>
27 #include <smp/spinlock.h>
28 #include <cpu/x86/mtrr.h>
29 #include <cpu/amd/model_10xxx_msr.h>
30 #include <cpu/amd/model_10xxx_rev.h>
31 #include <cpu/amd/amdfam10_sysconf.h>
33 extern device_t get_node_pci(u32 nodeid, u32 fn);
36 static int first_time = 1;
39 #include "quadcore_id.c"
41 static u32 get_max_siblings(u32 nodes)
47 //get max siblings from all the nodes
48 for(nodeid=0; nodeid<nodes; nodeid++){
50 dev = get_node_pci(nodeid, 3);
51 j = (pci_read_config32(dev, 0xe8) >> 12) & 3;
61 static void enable_apic_ext_id(u32 nodes)
66 //enable APIC_EXIT_ID all the nodes
67 for(nodeid=0; nodeid<nodes; nodeid++){
69 dev = get_node_pci(nodeid, 0);
70 val = pci_read_config32(dev, 0x68);
71 val |= (1<<17)|(1<<18);
72 pci_write_config32(dev, 0x68, val);
77 u32 get_apicid_base(u32 ioapic_num)
83 u32 disable_siblings = !CONFIG_LOGICAL_CPUS;
85 get_option(&disable_siblings, "quad_core");
87 siblings = get_max_siblings(sysconf.nodes);
89 if(sysconf.bsp_apicid > 0) { // io apic could start from 0
91 } else if (sysconf.enabled_apic_ext_id) { // enabled ext id but bsp = 0
95 nb_cfg_54 = read_nb_cfg_54();
98 //contruct apicid_base
100 if((!disable_siblings) && (siblings>0) ) {
101 /* for 8 way dual core, we will used up apicid 16:16, actualy
102 16 is not allowed by current kernel and the kernel will try
103 to get one that is small than 16 to make io apic work. I don't
104 know when the kernel can support 256 apic id.
105 (APIC_EXT_ID is enabled) */
107 //4:10 for two way 8:12 for four way 16:16 for eight way
108 //Use CONFIG_MAX_PHYSICAL_CPUS instead of nodes for better consistency?
109 apicid_base = nb_cfg_54 ? (siblings+1) * sysconf.nodes : 8 * siblings + sysconf.nodes;
112 apicid_base = sysconf.nodes;
115 if((apicid_base+ioapic_num-1)>0xf) {
116 // We need to enable APIC EXT ID
117 printk_spew("if the IO APIC device doesn't support 256 apic id, \r\n you need to set ENABLE_APIC_EXT_ID in MB Option.lb so you can spare 16 id for ioapic\r\n");
118 enable_apic_ext_id(sysconf.nodes);