Commit | Line | Data |
---|---|---|
3f4110a4 TG |
1 | /* |
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> | |
16ab5395 JP |
13 | #include <linux/kernel.h> |
14 | #include <linux/sfi.h> | |
15 | #include <linux/irq.h> | |
cf089455 | 16 | #include <linux/module.h> |
3f4110a4 TG |
17 | |
18 | #include <asm/setup.h> | |
16ab5395 JP |
19 | #include <asm/mpspec_def.h> |
20 | #include <asm/hw_irq.h> | |
21 | #include <asm/apic.h> | |
22 | #include <asm/io_apic.h> | |
5b78b672 JP |
23 | #include <asm/mrst.h> |
24 | #include <asm/io.h> | |
25 | #include <asm/i8259.h> | |
3746c6b6 | 26 | #include <asm/apb_timer.h> |
3f4110a4 | 27 | |
16ab5395 JP |
28 | static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM]; |
29 | static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM]; | |
30 | int sfi_mtimer_num; | |
31 | ||
cf089455 FT |
32 | struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX]; |
33 | EXPORT_SYMBOL_GPL(sfi_mrtc_array); | |
34 | int sfi_mrtc_num; | |
35 | ||
16ab5395 JP |
36 | static inline void assign_to_mp_irq(struct mpc_intsrc *m, |
37 | struct mpc_intsrc *mp_irq) | |
38 | { | |
39 | memcpy(mp_irq, m, sizeof(struct mpc_intsrc)); | |
40 | } | |
41 | ||
42 | static inline int mp_irq_cmp(struct mpc_intsrc *mp_irq, | |
43 | struct mpc_intsrc *m) | |
44 | { | |
45 | return memcmp(mp_irq, m, sizeof(struct mpc_intsrc)); | |
46 | } | |
47 | ||
48 | static void save_mp_irq(struct mpc_intsrc *m) | |
49 | { | |
50 | int i; | |
51 | ||
52 | for (i = 0; i < mp_irq_entries; i++) { | |
53 | if (!mp_irq_cmp(&mp_irqs[i], m)) | |
54 | return; | |
55 | } | |
56 | ||
57 | assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]); | |
58 | if (++mp_irq_entries == MAX_IRQ_SOURCES) | |
59 | panic("Max # of irq sources exceeded!!\n"); | |
60 | } | |
61 | ||
62 | /* parse all the mtimer info to a static mtimer array */ | |
63 | static int __init sfi_parse_mtmr(struct sfi_table_header *table) | |
64 | { | |
65 | struct sfi_table_simple *sb; | |
66 | struct sfi_timer_table_entry *pentry; | |
67 | struct mpc_intsrc mp_irq; | |
68 | int totallen; | |
69 | ||
70 | sb = (struct sfi_table_simple *)table; | |
71 | if (!sfi_mtimer_num) { | |
72 | sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb, | |
73 | struct sfi_timer_table_entry); | |
74 | pentry = (struct sfi_timer_table_entry *) sb->pentry; | |
75 | totallen = sfi_mtimer_num * sizeof(*pentry); | |
76 | memcpy(sfi_mtimer_array, pentry, totallen); | |
77 | } | |
78 | ||
79 | printk(KERN_INFO "SFI: MTIMER info (num = %d):\n", sfi_mtimer_num); | |
80 | pentry = sfi_mtimer_array; | |
81 | for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) { | |
82 | printk(KERN_INFO "timer[%d]: paddr = 0x%08x, freq = %dHz," | |
83 | " irq = %d\n", totallen, (u32)pentry->phys_addr, | |
84 | pentry->freq_hz, pentry->irq); | |
85 | if (!pentry->irq) | |
86 | continue; | |
87 | mp_irq.type = MP_IOAPIC; | |
88 | mp_irq.irqtype = mp_INT; | |
89 | /* triggering mode edge bit 2-3, active high polarity bit 0-1 */ | |
90 | mp_irq.irqflag = 5; | |
91 | mp_irq.srcbus = 0; | |
92 | mp_irq.srcbusirq = pentry->irq; /* IRQ */ | |
93 | mp_irq.dstapic = MP_APIC_ALL; | |
94 | mp_irq.dstirq = pentry->irq; | |
95 | save_mp_irq(&mp_irq); | |
96 | } | |
97 | ||
98 | return 0; | |
99 | } | |
100 | ||
101 | struct sfi_timer_table_entry *sfi_get_mtmr(int hint) | |
102 | { | |
103 | int i; | |
104 | if (hint < sfi_mtimer_num) { | |
105 | if (!sfi_mtimer_usage[hint]) { | |
106 | pr_debug("hint taken for timer %d irq %d\n",\ | |
107 | hint, sfi_mtimer_array[hint].irq); | |
108 | sfi_mtimer_usage[hint] = 1; | |
109 | return &sfi_mtimer_array[hint]; | |
110 | } | |
111 | } | |
112 | /* take the first timer available */ | |
113 | for (i = 0; i < sfi_mtimer_num;) { | |
114 | if (!sfi_mtimer_usage[i]) { | |
115 | sfi_mtimer_usage[i] = 1; | |
116 | return &sfi_mtimer_array[i]; | |
117 | } | |
118 | i++; | |
119 | } | |
120 | return NULL; | |
121 | } | |
122 | ||
123 | void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr) | |
124 | { | |
125 | int i; | |
126 | for (i = 0; i < sfi_mtimer_num;) { | |
127 | if (mtmr->irq == sfi_mtimer_array[i].irq) { | |
128 | sfi_mtimer_usage[i] = 0; | |
129 | return; | |
130 | } | |
131 | i++; | |
132 | } | |
133 | } | |
134 | ||
cf089455 FT |
135 | /* parse all the mrtc info to a global mrtc array */ |
136 | int __init sfi_parse_mrtc(struct sfi_table_header *table) | |
137 | { | |
138 | struct sfi_table_simple *sb; | |
139 | struct sfi_rtc_table_entry *pentry; | |
140 | struct mpc_intsrc mp_irq; | |
141 | ||
142 | int totallen; | |
143 | ||
144 | sb = (struct sfi_table_simple *)table; | |
145 | if (!sfi_mrtc_num) { | |
146 | sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb, | |
147 | struct sfi_rtc_table_entry); | |
148 | pentry = (struct sfi_rtc_table_entry *)sb->pentry; | |
149 | totallen = sfi_mrtc_num * sizeof(*pentry); | |
150 | memcpy(sfi_mrtc_array, pentry, totallen); | |
151 | } | |
152 | ||
153 | printk(KERN_INFO "SFI: RTC info (num = %d):\n", sfi_mrtc_num); | |
154 | pentry = sfi_mrtc_array; | |
155 | for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) { | |
156 | printk(KERN_INFO "RTC[%d]: paddr = 0x%08x, irq = %d\n", | |
157 | totallen, (u32)pentry->phys_addr, pentry->irq); | |
158 | mp_irq.type = MP_IOAPIC; | |
159 | mp_irq.irqtype = mp_INT; | |
160 | mp_irq.irqflag = 0; | |
161 | mp_irq.srcbus = 0; | |
162 | mp_irq.srcbusirq = pentry->irq; /* IRQ */ | |
163 | mp_irq.dstapic = MP_APIC_ALL; | |
164 | mp_irq.dstirq = pentry->irq; | |
165 | save_mp_irq(&mp_irq); | |
166 | } | |
167 | return 0; | |
168 | } | |
169 | ||
3746c6b6 JP |
170 | /* |
171 | * the secondary clock in Moorestown can be APBT or LAPIC clock, default to | |
172 | * APBT but cmdline option can also override it. | |
173 | */ | |
174 | static void __cpuinit mrst_setup_secondary_clock(void) | |
175 | { | |
176 | /* restore default lapic clock if disabled by cmdline */ | |
177 | if (disable_apbt_percpu) | |
178 | return setup_secondary_APIC_clock(); | |
179 | apbt_setup_secondary_clock(); | |
180 | } | |
181 | ||
182 | static unsigned long __init mrst_calibrate_tsc(void) | |
183 | { | |
184 | unsigned long flags, fast_calibrate; | |
185 | ||
186 | local_irq_save(flags); | |
187 | fast_calibrate = apbt_quick_calibrate(); | |
188 | local_irq_restore(flags); | |
189 | ||
190 | if (fast_calibrate) | |
191 | return fast_calibrate; | |
192 | ||
193 | return 0; | |
194 | } | |
195 | ||
196 | void __init mrst_time_init(void) | |
197 | { | |
198 | sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr); | |
199 | pre_init_apic_IRQ0(); | |
200 | apbt_time_init(); | |
201 | } | |
202 | ||
cf089455 FT |
203 | void __init mrst_rtc_init(void) |
204 | { | |
205 | sfi_table_parse(SFI_SIG_MRTC, NULL, NULL, sfi_parse_mrtc); | |
206 | } | |
207 | ||
3746c6b6 JP |
208 | /* |
209 | * if we use per cpu apb timer, the bootclock already setup. if we use lapic | |
210 | * timer and one apbt timer for broadcast, we need to set up lapic boot clock. | |
211 | */ | |
212 | static void __init mrst_setup_boot_clock(void) | |
213 | { | |
214 | pr_info("%s: per cpu apbt flag %d \n", __func__, disable_apbt_percpu); | |
215 | if (disable_apbt_percpu) | |
216 | setup_boot_APIC_clock(); | |
217 | }; | |
218 | ||
3f4110a4 TG |
219 | /* |
220 | * Moorestown specific x86_init function overrides and early setup | |
221 | * calls. | |
222 | */ | |
223 | void __init x86_mrst_early_setup(void) | |
224 | { | |
225 | x86_init.resources.probe_roms = x86_init_noop; | |
226 | x86_init.resources.reserve_resources = x86_init_noop; | |
5b78b672 | 227 | |
3746c6b6 JP |
228 | x86_init.timers.timer_init = mrst_time_init; |
229 | x86_init.timers.setup_percpu_clockev = mrst_setup_boot_clock; | |
230 | ||
231 | x86_init.irqs.pre_vector_init = x86_init_noop; | |
232 | ||
233 | x86_cpuinit.setup_percpu_clockev = mrst_setup_secondary_clock; | |
234 | ||
235 | x86_platform.calibrate_tsc = mrst_calibrate_tsc; | |
af2730f6 JP |
236 | x86_init.pci.init = pci_mrst_init; |
237 | x86_init.pci.fixup_irqs = x86_init_noop; | |
238 | ||
5b78b672 | 239 | legacy_pic = &null_legacy_pic; |
3f4110a4 | 240 | } |