mrst.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
  26. static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
  27. int sfi_mtimer_num;
  28. struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
  29. EXPORT_SYMBOL_GPL(sfi_mrtc_array);
  30. int sfi_mrtc_num;
  31. static inline void assign_to_mp_irq(struct mpc_intsrc *m,
  32. struct mpc_intsrc *mp_irq)
  33. {
  34. memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
  35. }
  36. static inline int mp_irq_cmp(struct mpc_intsrc *mp_irq,
  37. struct mpc_intsrc *m)
  38. {
  39. return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
  40. }
  41. static void save_mp_irq(struct mpc_intsrc *m)
  42. {
  43. int i;
  44. for (i = 0; i < mp_irq_entries; i++) {
  45. if (!mp_irq_cmp(&mp_irqs[i], m))
  46. return;
  47. }
  48. assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
  49. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  50. panic("Max # of irq sources exceeded!!\n");
  51. }
  52. /* parse all the mtimer info to a static mtimer array */
  53. static int __init sfi_parse_mtmr(struct sfi_table_header *table)
  54. {
  55. struct sfi_table_simple *sb;
  56. struct sfi_timer_table_entry *pentry;
  57. struct mpc_intsrc mp_irq;
  58. int totallen;
  59. sb = (struct sfi_table_simple *)table;
  60. if (!sfi_mtimer_num) {
  61. sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
  62. struct sfi_timer_table_entry);
  63. pentry = (struct sfi_timer_table_entry *) sb->pentry;
  64. totallen = sfi_mtimer_num * sizeof(*pentry);
  65. memcpy(sfi_mtimer_array, pentry, totallen);
  66. }
  67. printk(KERN_INFO "SFI: MTIMER info (num = %d):\n", sfi_mtimer_num);
  68. pentry = sfi_mtimer_array;
  69. for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
  70. printk(KERN_INFO "timer[%d]: paddr = 0x%08x, freq = %dHz,"
  71. " irq = %d\n", totallen, (u32)pentry->phys_addr,
  72. pentry->freq_hz, pentry->irq);
  73. if (!pentry->irq)
  74. continue;
  75. mp_irq.type = MP_IOAPIC;
  76. mp_irq.irqtype = mp_INT;
  77. /* triggering mode edge bit 2-3, active high polarity bit 0-1 */
  78. mp_irq.irqflag = 5;
  79. mp_irq.srcbus = 0;
  80. mp_irq.srcbusirq = pentry->irq; /* IRQ */
  81. mp_irq.dstapic = MP_APIC_ALL;
  82. mp_irq.dstirq = pentry->irq;
  83. save_mp_irq(&mp_irq);
  84. }
  85. return 0;
  86. }
  87. struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
  88. {
  89. int i;
  90. if (hint < sfi_mtimer_num) {
  91. if (!sfi_mtimer_usage[hint]) {
  92. pr_debug("hint taken for timer %d irq %d\n",\
  93. hint, sfi_mtimer_array[hint].irq);
  94. sfi_mtimer_usage[hint] = 1;
  95. return &sfi_mtimer_array[hint];
  96. }
  97. }
  98. /* take the first timer available */
  99. for (i = 0; i < sfi_mtimer_num;) {
  100. if (!sfi_mtimer_usage[i]) {
  101. sfi_mtimer_usage[i] = 1;
  102. return &sfi_mtimer_array[i];
  103. }
  104. i++;
  105. }
  106. return NULL;
  107. }
  108. void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
  109. {
  110. int i;
  111. for (i = 0; i < sfi_mtimer_num;) {
  112. if (mtmr->irq == sfi_mtimer_array[i].irq) {
  113. sfi_mtimer_usage[i] = 0;
  114. return;
  115. }
  116. i++;
  117. }
  118. }
  119. /* parse all the mrtc info to a global mrtc array */
  120. int __init sfi_parse_mrtc(struct sfi_table_header *table)
  121. {
  122. struct sfi_table_simple *sb;
  123. struct sfi_rtc_table_entry *pentry;
  124. struct mpc_intsrc mp_irq;
  125. int totallen;
  126. sb = (struct sfi_table_simple *)table;
  127. if (!sfi_mrtc_num) {
  128. sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb,
  129. struct sfi_rtc_table_entry);
  130. pentry = (struct sfi_rtc_table_entry *)sb->pentry;
  131. totallen = sfi_mrtc_num * sizeof(*pentry);
  132. memcpy(sfi_mrtc_array, pentry, totallen);
  133. }
  134. printk(KERN_INFO "SFI: RTC info (num = %d):\n", sfi_mrtc_num);
  135. pentry = sfi_mrtc_array;
  136. for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
  137. printk(KERN_INFO "RTC[%d]: paddr = 0x%08x, irq = %d\n",
  138. totallen, (u32)pentry->phys_addr, pentry->irq);
  139. mp_irq.type = MP_IOAPIC;
  140. mp_irq.irqtype = mp_INT;
  141. mp_irq.irqflag = 0;
  142. mp_irq.srcbus = 0;
  143. mp_irq.srcbusirq = pentry->irq; /* IRQ */
  144. mp_irq.dstapic = MP_APIC_ALL;
  145. mp_irq.dstirq = pentry->irq;
  146. save_mp_irq(&mp_irq);
  147. }
  148. return 0;
  149. }
  150. void __init mrst_rtc_init(void)
  151. {
  152. sfi_table_parse(SFI_SIG_MRTC, NULL, NULL, sfi_parse_mrtc);
  153. }
  154. /*
  155. * Moorestown specific x86_init function overrides and early setup
  156. * calls.
  157. */
  158. void __init x86_mrst_early_setup(void)
  159. {
  160. x86_init.resources.probe_roms = x86_init_noop;
  161. x86_init.resources.reserve_resources = x86_init_noop;
  162. x86_init.pci.init = pci_mrst_init;
  163. x86_init.pci.fixup_irqs = x86_init_noop;
  164. legacy_pic = &null_legacy_pic;
  165. }