mrst.c 6.4 KB

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