Thomas Gleixner | 3f4110a | 2009-08-29 14:54:20 +0200 | [diff] [blame] | 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> |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/sfi.h> |
| 15 | #include <linux/irq.h> |
Feng Tang | cf08945 | 2010-02-12 03:37:38 -0800 | [diff] [blame] | 16 | #include <linux/module.h> |
Thomas Gleixner | 3f4110a | 2009-08-29 14:54:20 +0200 | [diff] [blame] | 17 | |
| 18 | #include <asm/setup.h> |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 19 | #include <asm/mpspec_def.h> |
| 20 | #include <asm/hw_irq.h> |
| 21 | #include <asm/apic.h> |
| 22 | #include <asm/io_apic.h> |
Jacob Pan | 5b78b67 | 2010-02-12 02:29:11 -0800 | [diff] [blame] | 23 | #include <asm/mrst.h> |
| 24 | #include <asm/io.h> |
| 25 | #include <asm/i8259.h> |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 26 | #include <asm/apb_timer.h> |
Thomas Gleixner | 3f4110a | 2009-08-29 14:54:20 +0200 | [diff] [blame] | 27 | |
Jacob Pan | a875c01 | 2010-05-19 12:01:25 -0700 | [diff] [blame^] | 28 | /* |
| 29 | * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock, |
| 30 | * cmdline option x86_mrst_timer can be used to override the configuration |
| 31 | * to prefer one or the other. |
| 32 | * at runtime, there are basically three timer configurations: |
| 33 | * 1. per cpu apbt clock only |
| 34 | * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only |
| 35 | * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast. |
| 36 | * |
| 37 | * by default (without cmdline option), platform code first detects cpu type |
| 38 | * to see if we are on lincroft or penwell, then set up both lapic or apbt |
| 39 | * clocks accordingly. |
| 40 | * i.e. by default, medfield uses configuration #2, moorestown uses #1. |
| 41 | * config #3 is supported but not recommended on medfield. |
| 42 | * |
| 43 | * rating and feature summary: |
| 44 | * lapic (with C3STOP) --------- 100 |
| 45 | * apbt (always-on) ------------ 110 |
| 46 | * lapic (always-on,ARAT) ------ 150 |
| 47 | */ |
| 48 | |
| 49 | int mrst_timer_options __cpuinitdata; |
| 50 | |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 51 | static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM]; |
| 52 | static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM]; |
Jacob Pan | a0c173b | 2010-05-19 12:01:24 -0700 | [diff] [blame] | 53 | static int mrst_cpu_chip; |
| 54 | |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 55 | int sfi_mtimer_num; |
| 56 | |
Feng Tang | cf08945 | 2010-02-12 03:37:38 -0800 | [diff] [blame] | 57 | struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX]; |
| 58 | EXPORT_SYMBOL_GPL(sfi_mrtc_array); |
| 59 | int sfi_mrtc_num; |
| 60 | |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 61 | static inline void assign_to_mp_irq(struct mpc_intsrc *m, |
| 62 | struct mpc_intsrc *mp_irq) |
| 63 | { |
| 64 | memcpy(mp_irq, m, sizeof(struct mpc_intsrc)); |
| 65 | } |
| 66 | |
| 67 | static inline int mp_irq_cmp(struct mpc_intsrc *mp_irq, |
| 68 | struct mpc_intsrc *m) |
| 69 | { |
| 70 | return memcmp(mp_irq, m, sizeof(struct mpc_intsrc)); |
| 71 | } |
| 72 | |
| 73 | static void save_mp_irq(struct mpc_intsrc *m) |
| 74 | { |
| 75 | int i; |
| 76 | |
| 77 | for (i = 0; i < mp_irq_entries; i++) { |
| 78 | if (!mp_irq_cmp(&mp_irqs[i], m)) |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]); |
| 83 | if (++mp_irq_entries == MAX_IRQ_SOURCES) |
| 84 | panic("Max # of irq sources exceeded!!\n"); |
| 85 | } |
| 86 | |
| 87 | /* parse all the mtimer info to a static mtimer array */ |
| 88 | static int __init sfi_parse_mtmr(struct sfi_table_header *table) |
| 89 | { |
| 90 | struct sfi_table_simple *sb; |
| 91 | struct sfi_timer_table_entry *pentry; |
| 92 | struct mpc_intsrc mp_irq; |
| 93 | int totallen; |
| 94 | |
| 95 | sb = (struct sfi_table_simple *)table; |
| 96 | if (!sfi_mtimer_num) { |
| 97 | sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb, |
| 98 | struct sfi_timer_table_entry); |
| 99 | pentry = (struct sfi_timer_table_entry *) sb->pentry; |
| 100 | totallen = sfi_mtimer_num * sizeof(*pentry); |
| 101 | memcpy(sfi_mtimer_array, pentry, totallen); |
| 102 | } |
| 103 | |
| 104 | printk(KERN_INFO "SFI: MTIMER info (num = %d):\n", sfi_mtimer_num); |
| 105 | pentry = sfi_mtimer_array; |
| 106 | for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) { |
| 107 | printk(KERN_INFO "timer[%d]: paddr = 0x%08x, freq = %dHz," |
| 108 | " irq = %d\n", totallen, (u32)pentry->phys_addr, |
| 109 | pentry->freq_hz, pentry->irq); |
| 110 | if (!pentry->irq) |
| 111 | continue; |
| 112 | mp_irq.type = MP_IOAPIC; |
| 113 | mp_irq.irqtype = mp_INT; |
| 114 | /* triggering mode edge bit 2-3, active high polarity bit 0-1 */ |
| 115 | mp_irq.irqflag = 5; |
| 116 | mp_irq.srcbus = 0; |
| 117 | mp_irq.srcbusirq = pentry->irq; /* IRQ */ |
| 118 | mp_irq.dstapic = MP_APIC_ALL; |
| 119 | mp_irq.dstirq = pentry->irq; |
| 120 | save_mp_irq(&mp_irq); |
| 121 | } |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | struct sfi_timer_table_entry *sfi_get_mtmr(int hint) |
| 127 | { |
| 128 | int i; |
| 129 | if (hint < sfi_mtimer_num) { |
| 130 | if (!sfi_mtimer_usage[hint]) { |
| 131 | pr_debug("hint taken for timer %d irq %d\n",\ |
| 132 | hint, sfi_mtimer_array[hint].irq); |
| 133 | sfi_mtimer_usage[hint] = 1; |
| 134 | return &sfi_mtimer_array[hint]; |
| 135 | } |
| 136 | } |
| 137 | /* take the first timer available */ |
| 138 | for (i = 0; i < sfi_mtimer_num;) { |
| 139 | if (!sfi_mtimer_usage[i]) { |
| 140 | sfi_mtimer_usage[i] = 1; |
| 141 | return &sfi_mtimer_array[i]; |
| 142 | } |
| 143 | i++; |
| 144 | } |
| 145 | return NULL; |
| 146 | } |
| 147 | |
| 148 | void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr) |
| 149 | { |
| 150 | int i; |
| 151 | for (i = 0; i < sfi_mtimer_num;) { |
| 152 | if (mtmr->irq == sfi_mtimer_array[i].irq) { |
| 153 | sfi_mtimer_usage[i] = 0; |
| 154 | return; |
| 155 | } |
| 156 | i++; |
| 157 | } |
| 158 | } |
| 159 | |
Feng Tang | cf08945 | 2010-02-12 03:37:38 -0800 | [diff] [blame] | 160 | /* parse all the mrtc info to a global mrtc array */ |
| 161 | int __init sfi_parse_mrtc(struct sfi_table_header *table) |
| 162 | { |
| 163 | struct sfi_table_simple *sb; |
| 164 | struct sfi_rtc_table_entry *pentry; |
| 165 | struct mpc_intsrc mp_irq; |
| 166 | |
| 167 | int totallen; |
| 168 | |
| 169 | sb = (struct sfi_table_simple *)table; |
| 170 | if (!sfi_mrtc_num) { |
| 171 | sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb, |
| 172 | struct sfi_rtc_table_entry); |
| 173 | pentry = (struct sfi_rtc_table_entry *)sb->pentry; |
| 174 | totallen = sfi_mrtc_num * sizeof(*pentry); |
| 175 | memcpy(sfi_mrtc_array, pentry, totallen); |
| 176 | } |
| 177 | |
| 178 | printk(KERN_INFO "SFI: RTC info (num = %d):\n", sfi_mrtc_num); |
| 179 | pentry = sfi_mrtc_array; |
| 180 | for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) { |
| 181 | printk(KERN_INFO "RTC[%d]: paddr = 0x%08x, irq = %d\n", |
| 182 | totallen, (u32)pentry->phys_addr, pentry->irq); |
| 183 | mp_irq.type = MP_IOAPIC; |
| 184 | mp_irq.irqtype = mp_INT; |
| 185 | mp_irq.irqflag = 0; |
| 186 | mp_irq.srcbus = 0; |
| 187 | mp_irq.srcbusirq = pentry->irq; /* IRQ */ |
| 188 | mp_irq.dstapic = MP_APIC_ALL; |
| 189 | mp_irq.dstirq = pentry->irq; |
| 190 | save_mp_irq(&mp_irq); |
| 191 | } |
| 192 | return 0; |
| 193 | } |
| 194 | |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 195 | static unsigned long __init mrst_calibrate_tsc(void) |
| 196 | { |
| 197 | unsigned long flags, fast_calibrate; |
| 198 | |
| 199 | local_irq_save(flags); |
| 200 | fast_calibrate = apbt_quick_calibrate(); |
| 201 | local_irq_restore(flags); |
| 202 | |
| 203 | if (fast_calibrate) |
| 204 | return fast_calibrate; |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | void __init mrst_time_init(void) |
| 210 | { |
Jacob Pan | a875c01 | 2010-05-19 12:01:25 -0700 | [diff] [blame^] | 211 | switch (mrst_timer_options) { |
| 212 | case MRST_TIMER_APBT_ONLY: |
| 213 | break; |
| 214 | case MRST_TIMER_LAPIC_APBT: |
| 215 | x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock; |
| 216 | x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock; |
| 217 | break; |
| 218 | default: |
| 219 | if (!boot_cpu_has(X86_FEATURE_ARAT)) |
| 220 | break; |
| 221 | x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock; |
| 222 | x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock; |
| 223 | return; |
| 224 | } |
| 225 | /* we need at least one APB timer */ |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 226 | sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr); |
| 227 | pre_init_apic_IRQ0(); |
| 228 | apbt_time_init(); |
| 229 | } |
| 230 | |
Feng Tang | cf08945 | 2010-02-12 03:37:38 -0800 | [diff] [blame] | 231 | void __init mrst_rtc_init(void) |
| 232 | { |
| 233 | sfi_table_parse(SFI_SIG_MRTC, NULL, NULL, sfi_parse_mrtc); |
| 234 | } |
| 235 | |
Jacob Pan | a0c173b | 2010-05-19 12:01:24 -0700 | [diff] [blame] | 236 | int mrst_identify_cpu(void) |
| 237 | { |
| 238 | return mrst_cpu_chip; |
| 239 | } |
| 240 | EXPORT_SYMBOL_GPL(mrst_identify_cpu); |
| 241 | |
| 242 | void __cpuinit mrst_arch_setup(void) |
| 243 | { |
| 244 | if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27) |
| 245 | mrst_cpu_chip = MRST_CPU_CHIP_PENWELL; |
| 246 | else if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x26) |
| 247 | mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT; |
| 248 | else { |
| 249 | pr_err("Unknown Moorestown CPU (%d:%d), default to Lincroft\n", |
| 250 | boot_cpu_data.x86, boot_cpu_data.x86_model); |
| 251 | mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT; |
| 252 | } |
| 253 | pr_debug("Moorestown CPU %s identified\n", |
| 254 | (mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT) ? |
| 255 | "Lincroft" : "Penwell"); |
| 256 | } |
| 257 | |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 258 | /* |
Thomas Gleixner | 3f4110a | 2009-08-29 14:54:20 +0200 | [diff] [blame] | 259 | * Moorestown specific x86_init function overrides and early setup |
| 260 | * calls. |
| 261 | */ |
| 262 | void __init x86_mrst_early_setup(void) |
| 263 | { |
| 264 | x86_init.resources.probe_roms = x86_init_noop; |
| 265 | x86_init.resources.reserve_resources = x86_init_noop; |
Jacob Pan | 5b78b67 | 2010-02-12 02:29:11 -0800 | [diff] [blame] | 266 | |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 267 | x86_init.timers.timer_init = mrst_time_init; |
Jacob Pan | a875c01 | 2010-05-19 12:01:25 -0700 | [diff] [blame^] | 268 | x86_init.timers.setup_percpu_clockev = x86_init_noop; |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 269 | |
| 270 | x86_init.irqs.pre_vector_init = x86_init_noop; |
| 271 | |
Jacob Pan | a0c173b | 2010-05-19 12:01:24 -0700 | [diff] [blame] | 272 | x86_init.oem.arch_setup = mrst_arch_setup; |
| 273 | |
Jacob Pan | a875c01 | 2010-05-19 12:01:25 -0700 | [diff] [blame^] | 274 | x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock; |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 275 | |
| 276 | x86_platform.calibrate_tsc = mrst_calibrate_tsc; |
Jacob Pan | af2730f | 2010-02-12 10:31:47 -0800 | [diff] [blame] | 277 | x86_init.pci.init = pci_mrst_init; |
| 278 | x86_init.pci.fixup_irqs = x86_init_noop; |
| 279 | |
Jacob Pan | 5b78b67 | 2010-02-12 02:29:11 -0800 | [diff] [blame] | 280 | legacy_pic = &null_legacy_pic; |
Jacob Pan | fea24e2 | 2010-05-14 14:41:20 -0700 | [diff] [blame] | 281 | |
| 282 | /* Avoid searching for BIOS MP tables */ |
| 283 | x86_init.mpparse.find_smp_config = x86_init_noop; |
| 284 | x86_init.mpparse.get_smp_config = x86_init_uint_noop; |
| 285 | |
Thomas Gleixner | 3f4110a | 2009-08-29 14:54:20 +0200 | [diff] [blame] | 286 | } |
Jacob Pan | a875c01 | 2010-05-19 12:01:25 -0700 | [diff] [blame^] | 287 | |
| 288 | /* |
| 289 | * if user does not want to use per CPU apb timer, just give it a lower rating |
| 290 | * than local apic timer and skip the late per cpu timer init. |
| 291 | */ |
| 292 | static inline int __init setup_x86_mrst_timer(char *arg) |
| 293 | { |
| 294 | if (!arg) |
| 295 | return -EINVAL; |
| 296 | |
| 297 | if (strcmp("apbt_only", arg) == 0) |
| 298 | mrst_timer_options = MRST_TIMER_APBT_ONLY; |
| 299 | else if (strcmp("lapic_and_apbt", arg) == 0) |
| 300 | mrst_timer_options = MRST_TIMER_LAPIC_APBT; |
| 301 | else { |
| 302 | pr_warning("X86 MRST timer option %s not recognised" |
| 303 | " use x86_mrst_timer=apbt_only or lapic_and_apbt\n", |
| 304 | arg); |
| 305 | return -EINVAL; |
| 306 | } |
| 307 | return 0; |
| 308 | } |
| 309 | __setup("x86_mrst_timer=", setup_x86_mrst_timer); |