mrst.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 <asm/setup.h>
  17. #include <asm/mpspec_def.h>
  18. #include <asm/hw_irq.h>
  19. #include <asm/apic.h>
  20. #include <asm/io_apic.h>
  21. #include <asm/mrst.h>
  22. #include <asm/io.h>
  23. #include <asm/i8259.h>
  24. static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
  25. static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
  26. int sfi_mtimer_num;
  27. static inline void assign_to_mp_irq(struct mpc_intsrc *m,
  28. struct mpc_intsrc *mp_irq)
  29. {
  30. memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
  31. }
  32. static inline int mp_irq_cmp(struct mpc_intsrc *mp_irq,
  33. struct mpc_intsrc *m)
  34. {
  35. return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
  36. }
  37. static void save_mp_irq(struct mpc_intsrc *m)
  38. {
  39. int i;
  40. for (i = 0; i < mp_irq_entries; i++) {
  41. if (!mp_irq_cmp(&mp_irqs[i], m))
  42. return;
  43. }
  44. assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
  45. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  46. panic("Max # of irq sources exceeded!!\n");
  47. }
  48. /* parse all the mtimer info to a static mtimer array */
  49. static int __init sfi_parse_mtmr(struct sfi_table_header *table)
  50. {
  51. struct sfi_table_simple *sb;
  52. struct sfi_timer_table_entry *pentry;
  53. struct mpc_intsrc mp_irq;
  54. int totallen;
  55. sb = (struct sfi_table_simple *)table;
  56. if (!sfi_mtimer_num) {
  57. sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
  58. struct sfi_timer_table_entry);
  59. pentry = (struct sfi_timer_table_entry *) sb->pentry;
  60. totallen = sfi_mtimer_num * sizeof(*pentry);
  61. memcpy(sfi_mtimer_array, pentry, totallen);
  62. }
  63. printk(KERN_INFO "SFI: MTIMER info (num = %d):\n", sfi_mtimer_num);
  64. pentry = sfi_mtimer_array;
  65. for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
  66. printk(KERN_INFO "timer[%d]: paddr = 0x%08x, freq = %dHz,"
  67. " irq = %d\n", totallen, (u32)pentry->phys_addr,
  68. pentry->freq_hz, pentry->irq);
  69. if (!pentry->irq)
  70. continue;
  71. mp_irq.type = MP_IOAPIC;
  72. mp_irq.irqtype = mp_INT;
  73. /* triggering mode edge bit 2-3, active high polarity bit 0-1 */
  74. mp_irq.irqflag = 5;
  75. mp_irq.srcbus = 0;
  76. mp_irq.srcbusirq = pentry->irq; /* IRQ */
  77. mp_irq.dstapic = MP_APIC_ALL;
  78. mp_irq.dstirq = pentry->irq;
  79. save_mp_irq(&mp_irq);
  80. }
  81. return 0;
  82. }
  83. struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
  84. {
  85. int i;
  86. if (hint < sfi_mtimer_num) {
  87. if (!sfi_mtimer_usage[hint]) {
  88. pr_debug("hint taken for timer %d irq %d\n",\
  89. hint, sfi_mtimer_array[hint].irq);
  90. sfi_mtimer_usage[hint] = 1;
  91. return &sfi_mtimer_array[hint];
  92. }
  93. }
  94. /* take the first timer available */
  95. for (i = 0; i < sfi_mtimer_num;) {
  96. if (!sfi_mtimer_usage[i]) {
  97. sfi_mtimer_usage[i] = 1;
  98. return &sfi_mtimer_array[i];
  99. }
  100. i++;
  101. }
  102. return NULL;
  103. }
  104. void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
  105. {
  106. int i;
  107. for (i = 0; i < sfi_mtimer_num;) {
  108. if (mtmr->irq == sfi_mtimer_array[i].irq) {
  109. sfi_mtimer_usage[i] = 0;
  110. return;
  111. }
  112. i++;
  113. }
  114. }
  115. /*
  116. * Moorestown specific x86_init function overrides and early setup
  117. * calls.
  118. */
  119. void __init x86_mrst_early_setup(void)
  120. {
  121. x86_init.resources.probe_roms = x86_init_noop;
  122. x86_init.resources.reserve_resources = x86_init_noop;
  123. x86_init.pci.init = pci_mrst_init;
  124. x86_init.pci.fixup_irqs = x86_init_noop;
  125. legacy_pic = &null_legacy_pic;
  126. }