mrst.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. __cpuinitdata enum mrst_timer_options mrst_timer_options;
  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. enum mrst_cpu_type __mrst_cpu_chip;
  50. EXPORT_SYMBOL_GPL(__mrst_cpu_chip);
  51. int sfi_mtimer_num;
  52. struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
  53. EXPORT_SYMBOL_GPL(sfi_mrtc_array);
  54. int sfi_mrtc_num;
  55. static inline void assign_to_mp_irq(struct mpc_intsrc *m,
  56. struct mpc_intsrc *mp_irq)
  57. {
  58. memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
  59. }
  60. static inline int mp_irq_cmp(struct mpc_intsrc *mp_irq,
  61. struct mpc_intsrc *m)
  62. {
  63. return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
  64. }
  65. static void save_mp_irq(struct mpc_intsrc *m)
  66. {
  67. int i;
  68. for (i = 0; i < mp_irq_entries; i++) {
  69. if (!mp_irq_cmp(&mp_irqs[i], m))
  70. return;
  71. }
  72. assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
  73. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  74. panic("Max # of irq sources exceeded!!\n");
  75. }
  76. /* parse all the mtimer info to a static mtimer array */
  77. static int __init sfi_parse_mtmr(struct sfi_table_header *table)
  78. {
  79. struct sfi_table_simple *sb;
  80. struct sfi_timer_table_entry *pentry;
  81. struct mpc_intsrc mp_irq;
  82. int totallen;
  83. sb = (struct sfi_table_simple *)table;
  84. if (!sfi_mtimer_num) {
  85. sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
  86. struct sfi_timer_table_entry);
  87. pentry = (struct sfi_timer_table_entry *) sb->pentry;
  88. totallen = sfi_mtimer_num * sizeof(*pentry);
  89. memcpy(sfi_mtimer_array, pentry, totallen);
  90. }
  91. printk(KERN_INFO "SFI: MTIMER info (num = %d):\n", sfi_mtimer_num);
  92. pentry = sfi_mtimer_array;
  93. for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
  94. printk(KERN_INFO "timer[%d]: paddr = 0x%08x, freq = %dHz,"
  95. " irq = %d\n", totallen, (u32)pentry->phys_addr,
  96. pentry->freq_hz, pentry->irq);
  97. if (!pentry->irq)
  98. continue;
  99. mp_irq.type = MP_IOAPIC;
  100. mp_irq.irqtype = mp_INT;
  101. /* triggering mode edge bit 2-3, active high polarity bit 0-1 */
  102. mp_irq.irqflag = 5;
  103. mp_irq.srcbus = 0;
  104. mp_irq.srcbusirq = pentry->irq; /* IRQ */
  105. mp_irq.dstapic = MP_APIC_ALL;
  106. mp_irq.dstirq = pentry->irq;
  107. save_mp_irq(&mp_irq);
  108. }
  109. return 0;
  110. }
  111. struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
  112. {
  113. int i;
  114. if (hint < sfi_mtimer_num) {
  115. if (!sfi_mtimer_usage[hint]) {
  116. pr_debug("hint taken for timer %d irq %d\n",\
  117. hint, sfi_mtimer_array[hint].irq);
  118. sfi_mtimer_usage[hint] = 1;
  119. return &sfi_mtimer_array[hint];
  120. }
  121. }
  122. /* take the first timer available */
  123. for (i = 0; i < sfi_mtimer_num;) {
  124. if (!sfi_mtimer_usage[i]) {
  125. sfi_mtimer_usage[i] = 1;
  126. return &sfi_mtimer_array[i];
  127. }
  128. i++;
  129. }
  130. return NULL;
  131. }
  132. void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
  133. {
  134. int i;
  135. for (i = 0; i < sfi_mtimer_num;) {
  136. if (mtmr->irq == sfi_mtimer_array[i].irq) {
  137. sfi_mtimer_usage[i] = 0;
  138. return;
  139. }
  140. i++;
  141. }
  142. }
  143. /* parse all the mrtc info to a global mrtc array */
  144. int __init sfi_parse_mrtc(struct sfi_table_header *table)
  145. {
  146. struct sfi_table_simple *sb;
  147. struct sfi_rtc_table_entry *pentry;
  148. struct mpc_intsrc mp_irq;
  149. int totallen;
  150. sb = (struct sfi_table_simple *)table;
  151. if (!sfi_mrtc_num) {
  152. sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb,
  153. struct sfi_rtc_table_entry);
  154. pentry = (struct sfi_rtc_table_entry *)sb->pentry;
  155. totallen = sfi_mrtc_num * sizeof(*pentry);
  156. memcpy(sfi_mrtc_array, pentry, totallen);
  157. }
  158. printk(KERN_INFO "SFI: RTC info (num = %d):\n", sfi_mrtc_num);
  159. pentry = sfi_mrtc_array;
  160. for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
  161. printk(KERN_INFO "RTC[%d]: paddr = 0x%08x, irq = %d\n",
  162. totallen, (u32)pentry->phys_addr, pentry->irq);
  163. mp_irq.type = MP_IOAPIC;
  164. mp_irq.irqtype = mp_INT;
  165. mp_irq.irqflag = 0;
  166. mp_irq.srcbus = 0;
  167. mp_irq.srcbusirq = pentry->irq; /* IRQ */
  168. mp_irq.dstapic = MP_APIC_ALL;
  169. mp_irq.dstirq = pentry->irq;
  170. save_mp_irq(&mp_irq);
  171. }
  172. return 0;
  173. }
  174. static unsigned long __init mrst_calibrate_tsc(void)
  175. {
  176. unsigned long flags, fast_calibrate;
  177. local_irq_save(flags);
  178. fast_calibrate = apbt_quick_calibrate();
  179. local_irq_restore(flags);
  180. if (fast_calibrate)
  181. return fast_calibrate;
  182. return 0;
  183. }
  184. void __init mrst_time_init(void)
  185. {
  186. switch (mrst_timer_options) {
  187. case MRST_TIMER_APBT_ONLY:
  188. break;
  189. case MRST_TIMER_LAPIC_APBT:
  190. x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
  191. x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
  192. break;
  193. default:
  194. if (!boot_cpu_has(X86_FEATURE_ARAT))
  195. break;
  196. x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
  197. x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
  198. return;
  199. }
  200. /* we need at least one APB timer */
  201. sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
  202. pre_init_apic_IRQ0();
  203. apbt_time_init();
  204. }
  205. void __init mrst_rtc_init(void)
  206. {
  207. sfi_table_parse(SFI_SIG_MRTC, NULL, NULL, sfi_parse_mrtc);
  208. }
  209. void __cpuinit mrst_arch_setup(void)
  210. {
  211. if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
  212. __mrst_cpu_chip = MRST_CPU_CHIP_PENWELL;
  213. else if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x26)
  214. __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
  215. else {
  216. pr_err("Unknown Moorestown CPU (%d:%d), default to Lincroft\n",
  217. boot_cpu_data.x86, boot_cpu_data.x86_model);
  218. __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
  219. }
  220. pr_debug("Moorestown CPU %s identified\n",
  221. (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT) ?
  222. "Lincroft" : "Penwell");
  223. }
  224. /* MID systems don't have i8042 controller */
  225. static int mrst_i8042_detect(void)
  226. {
  227. return 0;
  228. }
  229. /*
  230. * Moorestown specific x86_init function overrides and early setup
  231. * calls.
  232. */
  233. void __init x86_mrst_early_setup(void)
  234. {
  235. x86_init.resources.probe_roms = x86_init_noop;
  236. x86_init.resources.reserve_resources = x86_init_noop;
  237. x86_init.timers.timer_init = mrst_time_init;
  238. x86_init.timers.setup_percpu_clockev = x86_init_noop;
  239. x86_init.irqs.pre_vector_init = x86_init_noop;
  240. x86_init.oem.arch_setup = mrst_arch_setup;
  241. x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
  242. x86_platform.calibrate_tsc = mrst_calibrate_tsc;
  243. x86_platform.i8042_detect = mrst_i8042_detect;
  244. x86_init.pci.init = pci_mrst_init;
  245. x86_init.pci.fixup_irqs = x86_init_noop;
  246. legacy_pic = &null_legacy_pic;
  247. /* Avoid searching for BIOS MP tables */
  248. x86_init.mpparse.find_smp_config = x86_init_noop;
  249. x86_init.mpparse.get_smp_config = x86_init_uint_noop;
  250. }
  251. /*
  252. * if user does not want to use per CPU apb timer, just give it a lower rating
  253. * than local apic timer and skip the late per cpu timer init.
  254. */
  255. static inline int __init setup_x86_mrst_timer(char *arg)
  256. {
  257. if (!arg)
  258. return -EINVAL;
  259. if (strcmp("apbt_only", arg) == 0)
  260. mrst_timer_options = MRST_TIMER_APBT_ONLY;
  261. else if (strcmp("lapic_and_apbt", arg) == 0)
  262. mrst_timer_options = MRST_TIMER_LAPIC_APBT;
  263. else {
  264. pr_warning("X86 MRST timer option %s not recognised"
  265. " use x86_mrst_timer=apbt_only or lapic_and_apbt\n",
  266. arg);
  267. return -EINVAL;
  268. }
  269. return 0;
  270. }
  271. __setup("x86_mrst_timer=", setup_x86_mrst_timer);