- Update Xen patches to 3.3-rc5 and c/s 1157.
[linux-flexiantxendom0-3.2.10.git] / arch / x86 / platform / sfi / sfi.c
1 /*
2  * sfi.c - x86 architecture SFI support.
3  *
4  * Copyright (c) 2009, Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  */
20
21 #define KMSG_COMPONENT "SFI"
22 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
23
24 #include <linux/acpi.h>
25 #include <linux/init.h>
26 #include <linux/sfi.h>
27 #include <linux/io.h>
28
29 #include <asm/io_apic.h>
30 #include <asm/mpspec.h>
31 #include <asm/setup.h>
32 #include <asm/apic.h>
33
34 #ifdef CONFIG_X86_LOCAL_APIC
35 #ifndef CONFIG_XEN
36 static unsigned long sfi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
37
38 /* All CPUs enumerated by SFI must be present and enabled */
39 static void __cpuinit mp_sfi_register_lapic(u8 id)
40 {
41         if (MAX_LOCAL_APIC - id <= 0) {
42                 pr_warning("Processor #%d invalid (max %d)\n",
43                         id, MAX_LOCAL_APIC);
44                 return;
45         }
46
47         pr_info("registering lapic[%d]\n", id);
48
49         generic_processor_info(id, GET_APIC_VERSION(apic_read(APIC_LVR)));
50 }
51 #else
52 #define mp_sfi_register_lapic(id)
53 #endif
54
55 static int __init sfi_parse_cpus(struct sfi_table_header *table)
56 {
57         struct sfi_table_simple *sb;
58         struct sfi_cpu_table_entry *pentry;
59         int i;
60         int cpu_num;
61
62         sb = (struct sfi_table_simple *)table;
63         cpu_num = SFI_GET_NUM_ENTRIES(sb, struct sfi_cpu_table_entry);
64         pentry = (struct sfi_cpu_table_entry *)sb->pentry;
65
66         for (i = 0; i < cpu_num; i++) {
67                 mp_sfi_register_lapic(pentry->apic_id);
68                 pentry++;
69         }
70
71         smp_found_config = 1;
72         return 0;
73 }
74 #endif /* CONFIG_X86_LOCAL_APIC */
75
76 #ifdef CONFIG_X86_IO_APIC
77
78 static int __init sfi_parse_ioapic(struct sfi_table_header *table)
79 {
80         struct sfi_table_simple *sb;
81         struct sfi_apic_table_entry *pentry;
82         int i, num;
83
84         sb = (struct sfi_table_simple *)table;
85         num = SFI_GET_NUM_ENTRIES(sb, struct sfi_apic_table_entry);
86         pentry = (struct sfi_apic_table_entry *)sb->pentry;
87
88         for (i = 0; i < num; i++) {
89                 mp_register_ioapic(i, pentry->phys_addr, gsi_top);
90                 pentry++;
91         }
92
93 #ifndef CONFIG_XEN
94         WARN(pic_mode, KERN_WARNING
95                 "SFI: pic_mod shouldn't be 1 when IOAPIC table is present\n");
96         pic_mode = 0;
97 #endif
98
99         return 0;
100 }
101 #endif /* CONFIG_X86_IO_APIC */
102
103 /*
104  * sfi_platform_init(): register lapics & io-apics
105  */
106 int __init sfi_platform_init(void)
107 {
108 #ifdef CONFIG_X86_LOCAL_APIC
109         register_lapic_address(sfi_lapic_addr);
110         sfi_table_parse(SFI_SIG_CPUS, NULL, NULL, sfi_parse_cpus);
111 #endif
112 #ifdef CONFIG_X86_IO_APIC
113         sfi_table_parse(SFI_SIG_APIC, NULL, NULL, sfi_parse_ioapic);
114 #endif
115         return 0;
116 }