mrst.c 6.9 KB

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