2 * mrst.c: Intel Moorestown platform specific setup code
4 * (C) Copyright 2008 Intel Corporation
5 * Author: Jacob Pan (jacob.jun.pan@intel.com)
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
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>
18 #include <asm/setup.h>
19 #include <asm/mpspec_def.h>
20 #include <asm/hw_irq.h>
22 #include <asm/io_apic.h>
25 #include <asm/i8259.h>
27 static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
28 static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
31 struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
32 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
35 static inline void assign_to_mp_irq(struct mpc_intsrc *m,
36 struct mpc_intsrc *mp_irq)
38 memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
41 static inline int mp_irq_cmp(struct mpc_intsrc *mp_irq,
44 return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
47 static void save_mp_irq(struct mpc_intsrc *m)
51 for (i = 0; i < mp_irq_entries; i++) {
52 if (!mp_irq_cmp(&mp_irqs[i], m))
56 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
57 if (++mp_irq_entries == MAX_IRQ_SOURCES)
58 panic("Max # of irq sources exceeded!!\n");
61 /* parse all the mtimer info to a static mtimer array */
62 static int __init sfi_parse_mtmr(struct sfi_table_header *table)
64 struct sfi_table_simple *sb;
65 struct sfi_timer_table_entry *pentry;
66 struct mpc_intsrc mp_irq;
69 sb = (struct sfi_table_simple *)table;
70 if (!sfi_mtimer_num) {
71 sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
72 struct sfi_timer_table_entry);
73 pentry = (struct sfi_timer_table_entry *) sb->pentry;
74 totallen = sfi_mtimer_num * sizeof(*pentry);
75 memcpy(sfi_mtimer_array, pentry, totallen);
78 printk(KERN_INFO "SFI: MTIMER info (num = %d):\n", sfi_mtimer_num);
79 pentry = sfi_mtimer_array;
80 for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
81 printk(KERN_INFO "timer[%d]: paddr = 0x%08x, freq = %dHz,"
82 " irq = %d\n", totallen, (u32)pentry->phys_addr,
83 pentry->freq_hz, pentry->irq);
86 mp_irq.type = MP_IOAPIC;
87 mp_irq.irqtype = mp_INT;
88 /* triggering mode edge bit 2-3, active high polarity bit 0-1 */
91 mp_irq.srcbusirq = pentry->irq; /* IRQ */
92 mp_irq.dstapic = MP_APIC_ALL;
93 mp_irq.dstirq = pentry->irq;
100 struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
103 if (hint < sfi_mtimer_num) {
104 if (!sfi_mtimer_usage[hint]) {
105 pr_debug("hint taken for timer %d irq %d\n",\
106 hint, sfi_mtimer_array[hint].irq);
107 sfi_mtimer_usage[hint] = 1;
108 return &sfi_mtimer_array[hint];
111 /* take the first timer available */
112 for (i = 0; i < sfi_mtimer_num;) {
113 if (!sfi_mtimer_usage[i]) {
114 sfi_mtimer_usage[i] = 1;
115 return &sfi_mtimer_array[i];
122 void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
125 for (i = 0; i < sfi_mtimer_num;) {
126 if (mtmr->irq == sfi_mtimer_array[i].irq) {
127 sfi_mtimer_usage[i] = 0;
134 /* parse all the mrtc info to a global mrtc array */
135 int __init sfi_parse_mrtc(struct sfi_table_header *table)
137 struct sfi_table_simple *sb;
138 struct sfi_rtc_table_entry *pentry;
139 struct mpc_intsrc mp_irq;
143 sb = (struct sfi_table_simple *)table;
145 sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb,
146 struct sfi_rtc_table_entry);
147 pentry = (struct sfi_rtc_table_entry *)sb->pentry;
148 totallen = sfi_mrtc_num * sizeof(*pentry);
149 memcpy(sfi_mrtc_array, pentry, totallen);
152 printk(KERN_INFO "SFI: RTC info (num = %d):\n", sfi_mrtc_num);
153 pentry = sfi_mrtc_array;
154 for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
155 printk(KERN_INFO "RTC[%d]: paddr = 0x%08x, irq = %d\n",
156 totallen, (u32)pentry->phys_addr, pentry->irq);
157 mp_irq.type = MP_IOAPIC;
158 mp_irq.irqtype = mp_INT;
161 mp_irq.srcbusirq = pentry->irq; /* IRQ */
162 mp_irq.dstapic = MP_APIC_ALL;
163 mp_irq.dstirq = pentry->irq;
164 save_mp_irq(&mp_irq);
169 void __init mrst_rtc_init(void)
171 sfi_table_parse(SFI_SIG_MRTC, NULL, NULL, sfi_parse_mrtc);
175 * Moorestown specific x86_init function overrides and early setup
178 void __init x86_mrst_early_setup(void)
180 x86_init.resources.probe_roms = x86_init_noop;
181 x86_init.resources.reserve_resources = x86_init_noop;
183 x86_init.pci.init = pci_mrst_init;
184 x86_init.pci.fixup_irqs = x86_init_noop;
186 legacy_pic = &null_legacy_pic;