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