blob: ceaebeb5866f00b29c05a9d439f9535c6d7a6aa6 [file] [log] [blame]
Thomas Gleixner3f4110a2009-08-29 14:54:20 +02001/*
2 * mrst.c: Intel Moorestown platform specific setup code
3 *
4 * (C) Copyright 2008 Intel Corporation
5 * Author: Jacob Pan (jacob.jun.pan@intel.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; version 2
10 * of the License.
11 */
12#include <linux/init.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080013#include <linux/kernel.h>
14#include <linux/sfi.h>
15#include <linux/irq.h>
Feng Tangcf089452010-02-12 03:37:38 -080016#include <linux/module.h>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020017
18#include <asm/setup.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080019#include <asm/mpspec_def.h>
20#include <asm/hw_irq.h>
21#include <asm/apic.h>
22#include <asm/io_apic.h>
Jacob Pan5b78b672010-02-12 02:29:11 -080023#include <asm/mrst.h>
24#include <asm/io.h>
25#include <asm/i8259.h>
Jacob Pan3746c6b2010-02-12 05:01:12 -080026#include <asm/apb_timer.h>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020027
Jacob Pan16ab5392010-02-12 03:08:30 -080028static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
29static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
Jacob Pana0c173b2010-05-19 12:01:24 -070030static int mrst_cpu_chip;
31
Jacob Pan16ab5392010-02-12 03:08:30 -080032int sfi_mtimer_num;
33
Feng Tangcf089452010-02-12 03:37:38 -080034struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
35EXPORT_SYMBOL_GPL(sfi_mrtc_array);
36int sfi_mrtc_num;
37
Jacob Pan16ab5392010-02-12 03:08:30 -080038static inline void assign_to_mp_irq(struct mpc_intsrc *m,
39 struct mpc_intsrc *mp_irq)
40{
41 memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
42}
43
44static inline int mp_irq_cmp(struct mpc_intsrc *mp_irq,
45 struct mpc_intsrc *m)
46{
47 return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
48}
49
50static void save_mp_irq(struct mpc_intsrc *m)
51{
52 int i;
53
54 for (i = 0; i < mp_irq_entries; i++) {
55 if (!mp_irq_cmp(&mp_irqs[i], m))
56 return;
57 }
58
59 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
60 if (++mp_irq_entries == MAX_IRQ_SOURCES)
61 panic("Max # of irq sources exceeded!!\n");
62}
63
64/* parse all the mtimer info to a static mtimer array */
65static int __init sfi_parse_mtmr(struct sfi_table_header *table)
66{
67 struct sfi_table_simple *sb;
68 struct sfi_timer_table_entry *pentry;
69 struct mpc_intsrc mp_irq;
70 int totallen;
71
72 sb = (struct sfi_table_simple *)table;
73 if (!sfi_mtimer_num) {
74 sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
75 struct sfi_timer_table_entry);
76 pentry = (struct sfi_timer_table_entry *) sb->pentry;
77 totallen = sfi_mtimer_num * sizeof(*pentry);
78 memcpy(sfi_mtimer_array, pentry, totallen);
79 }
80
81 printk(KERN_INFO "SFI: MTIMER info (num = %d):\n", sfi_mtimer_num);
82 pentry = sfi_mtimer_array;
83 for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
84 printk(KERN_INFO "timer[%d]: paddr = 0x%08x, freq = %dHz,"
85 " irq = %d\n", totallen, (u32)pentry->phys_addr,
86 pentry->freq_hz, pentry->irq);
87 if (!pentry->irq)
88 continue;
89 mp_irq.type = MP_IOAPIC;
90 mp_irq.irqtype = mp_INT;
91/* triggering mode edge bit 2-3, active high polarity bit 0-1 */
92 mp_irq.irqflag = 5;
93 mp_irq.srcbus = 0;
94 mp_irq.srcbusirq = pentry->irq; /* IRQ */
95 mp_irq.dstapic = MP_APIC_ALL;
96 mp_irq.dstirq = pentry->irq;
97 save_mp_irq(&mp_irq);
98 }
99
100 return 0;
101}
102
103struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
104{
105 int i;
106 if (hint < sfi_mtimer_num) {
107 if (!sfi_mtimer_usage[hint]) {
108 pr_debug("hint taken for timer %d irq %d\n",\
109 hint, sfi_mtimer_array[hint].irq);
110 sfi_mtimer_usage[hint] = 1;
111 return &sfi_mtimer_array[hint];
112 }
113 }
114 /* take the first timer available */
115 for (i = 0; i < sfi_mtimer_num;) {
116 if (!sfi_mtimer_usage[i]) {
117 sfi_mtimer_usage[i] = 1;
118 return &sfi_mtimer_array[i];
119 }
120 i++;
121 }
122 return NULL;
123}
124
125void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
126{
127 int i;
128 for (i = 0; i < sfi_mtimer_num;) {
129 if (mtmr->irq == sfi_mtimer_array[i].irq) {
130 sfi_mtimer_usage[i] = 0;
131 return;
132 }
133 i++;
134 }
135}
136
Feng Tangcf089452010-02-12 03:37:38 -0800137/* parse all the mrtc info to a global mrtc array */
138int __init sfi_parse_mrtc(struct sfi_table_header *table)
139{
140 struct sfi_table_simple *sb;
141 struct sfi_rtc_table_entry *pentry;
142 struct mpc_intsrc mp_irq;
143
144 int totallen;
145
146 sb = (struct sfi_table_simple *)table;
147 if (!sfi_mrtc_num) {
148 sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb,
149 struct sfi_rtc_table_entry);
150 pentry = (struct sfi_rtc_table_entry *)sb->pentry;
151 totallen = sfi_mrtc_num * sizeof(*pentry);
152 memcpy(sfi_mrtc_array, pentry, totallen);
153 }
154
155 printk(KERN_INFO "SFI: RTC info (num = %d):\n", sfi_mrtc_num);
156 pentry = sfi_mrtc_array;
157 for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
158 printk(KERN_INFO "RTC[%d]: paddr = 0x%08x, irq = %d\n",
159 totallen, (u32)pentry->phys_addr, pentry->irq);
160 mp_irq.type = MP_IOAPIC;
161 mp_irq.irqtype = mp_INT;
162 mp_irq.irqflag = 0;
163 mp_irq.srcbus = 0;
164 mp_irq.srcbusirq = pentry->irq; /* IRQ */
165 mp_irq.dstapic = MP_APIC_ALL;
166 mp_irq.dstirq = pentry->irq;
167 save_mp_irq(&mp_irq);
168 }
169 return 0;
170}
171
Jacob Pan3746c6b2010-02-12 05:01:12 -0800172/*
173 * the secondary clock in Moorestown can be APBT or LAPIC clock, default to
174 * APBT but cmdline option can also override it.
175 */
176static void __cpuinit mrst_setup_secondary_clock(void)
177{
178 /* restore default lapic clock if disabled by cmdline */
179 if (disable_apbt_percpu)
180 return setup_secondary_APIC_clock();
181 apbt_setup_secondary_clock();
182}
183
184static unsigned long __init mrst_calibrate_tsc(void)
185{
186 unsigned long flags, fast_calibrate;
187
188 local_irq_save(flags);
189 fast_calibrate = apbt_quick_calibrate();
190 local_irq_restore(flags);
191
192 if (fast_calibrate)
193 return fast_calibrate;
194
195 return 0;
196}
197
198void __init mrst_time_init(void)
199{
200 sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
201 pre_init_apic_IRQ0();
202 apbt_time_init();
203}
204
Feng Tangcf089452010-02-12 03:37:38 -0800205void __init mrst_rtc_init(void)
206{
207 sfi_table_parse(SFI_SIG_MRTC, NULL, NULL, sfi_parse_mrtc);
208}
209
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200210/*
Jacob Pan3746c6b2010-02-12 05:01:12 -0800211 * if we use per cpu apb timer, the bootclock already setup. if we use lapic
212 * timer and one apbt timer for broadcast, we need to set up lapic boot clock.
213 */
214static void __init mrst_setup_boot_clock(void)
215{
216 pr_info("%s: per cpu apbt flag %d \n", __func__, disable_apbt_percpu);
217 if (disable_apbt_percpu)
218 setup_boot_APIC_clock();
219};
220
Jacob Pana0c173b2010-05-19 12:01:24 -0700221int mrst_identify_cpu(void)
222{
223 return mrst_cpu_chip;
224}
225EXPORT_SYMBOL_GPL(mrst_identify_cpu);
226
227void __cpuinit mrst_arch_setup(void)
228{
229 if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
230 mrst_cpu_chip = MRST_CPU_CHIP_PENWELL;
231 else if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x26)
232 mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
233 else {
234 pr_err("Unknown Moorestown CPU (%d:%d), default to Lincroft\n",
235 boot_cpu_data.x86, boot_cpu_data.x86_model);
236 mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
237 }
238 pr_debug("Moorestown CPU %s identified\n",
239 (mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT) ?
240 "Lincroft" : "Penwell");
241}
242
Jacob Pan3746c6b2010-02-12 05:01:12 -0800243/*
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200244 * Moorestown specific x86_init function overrides and early setup
245 * calls.
246 */
247void __init x86_mrst_early_setup(void)
248{
249 x86_init.resources.probe_roms = x86_init_noop;
250 x86_init.resources.reserve_resources = x86_init_noop;
Jacob Pan5b78b672010-02-12 02:29:11 -0800251
Jacob Pan3746c6b2010-02-12 05:01:12 -0800252 x86_init.timers.timer_init = mrst_time_init;
253 x86_init.timers.setup_percpu_clockev = mrst_setup_boot_clock;
254
255 x86_init.irqs.pre_vector_init = x86_init_noop;
256
Jacob Pana0c173b2010-05-19 12:01:24 -0700257 x86_init.oem.arch_setup = mrst_arch_setup;
258
Jacob Pan3746c6b2010-02-12 05:01:12 -0800259 x86_cpuinit.setup_percpu_clockev = mrst_setup_secondary_clock;
260
261 x86_platform.calibrate_tsc = mrst_calibrate_tsc;
Jacob Panaf2730f2010-02-12 10:31:47 -0800262 x86_init.pci.init = pci_mrst_init;
263 x86_init.pci.fixup_irqs = x86_init_noop;
264
Jacob Pan5b78b672010-02-12 02:29:11 -0800265 legacy_pic = &null_legacy_pic;
Jacob Panfea24e22010-05-14 14:41:20 -0700266
267 /* Avoid searching for BIOS MP tables */
268 x86_init.mpparse.find_smp_config = x86_init_noop;
269 x86_init.mpparse.get_smp_config = x86_init_uint_noop;
270
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200271}