mrst.c 8.2 KB

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