Vegard Nossum | 77ef50a | 2008-06-18 17:08:48 +0200 | [diff] [blame] | 1 | #ifndef ASM_X86__MACH_DEFAULT__MACH_APIC_H |
| 2 | #define ASM_X86__MACH_DEFAULT__MACH_APIC_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 4 | #ifdef CONFIG_X86_LOCAL_APIC |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <mach_apicdef.h> |
| 7 | #include <asm/smp.h> |
| 8 | |
| 9 | #define APIC_DFR_VALUE (APIC_DFR_FLAT) |
| 10 | |
| 11 | static inline cpumask_t target_cpus(void) |
| 12 | { |
| 13 | #ifdef CONFIG_SMP |
| 14 | return cpu_online_map; |
| 15 | #else |
| 16 | return cpumask_of_cpu(0); |
| 17 | #endif |
| 18 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #define NO_BALANCE_IRQ (0) |
| 21 | #define esr_disable (0) |
| 22 | |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 23 | #ifdef CONFIG_X86_64 |
| 24 | #include <asm/genapic.h> |
| 25 | #define INT_DELIVERY_MODE (genapic->int_delivery_mode) |
| 26 | #define INT_DEST_MODE (genapic->int_dest_mode) |
| 27 | #define TARGET_CPUS (genapic->target_cpus()) |
| 28 | #define apic_id_registered (genapic->apic_id_registered) |
| 29 | #define init_apic_ldr (genapic->init_apic_ldr) |
| 30 | #define cpu_mask_to_apicid (genapic->cpu_mask_to_apicid) |
| 31 | #define phys_pkg_id (genapic->phys_pkg_id) |
| 32 | #define vector_allocation_domain (genapic->vector_allocation_domain) |
Yinghai Lu | f910a9d | 2008-07-12 01:01:20 -0700 | [diff] [blame] | 33 | #define read_apic_id() (GET_APIC_ID(apic_read(APIC_ID))) |
Suresh Siddha | cff73a6 | 2008-07-10 11:16:53 -0700 | [diff] [blame] | 34 | #define send_IPI_self (genapic->send_IPI_self) |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 35 | extern void setup_apic_routing(void); |
| 36 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #define INT_DELIVERY_MODE dest_LowestPrio |
| 38 | #define INT_DEST_MODE 1 /* logical delivery broadcast to all procs */ |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 39 | #define TARGET_CPUS (target_cpus()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Set up the logical destination ID. |
| 42 | * |
| 43 | * Intel recommends to set DFR, LDR and TPR before enabling |
| 44 | * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel |
| 45 | * document number 292116). So here it goes... |
| 46 | */ |
| 47 | static inline void init_apic_ldr(void) |
| 48 | { |
| 49 | unsigned long val; |
| 50 | |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 51 | apic_write(APIC_DFR, APIC_DFR_VALUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | val = apic_read(APIC_LDR) & ~APIC_LDR_MASK; |
| 53 | val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id()); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 54 | apic_write(APIC_LDR, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 57 | static inline int apic_id_registered(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 59 | return physid_isset(read_apic_id(), phys_cpu_present_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 62 | static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask) |
| 63 | { |
| 64 | return cpus_addr(cpumask)[0]; |
| 65 | } |
| 66 | |
| 67 | static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb) |
| 68 | { |
| 69 | return cpuid_apic >> index_msb; |
| 70 | } |
| 71 | |
Ingo Molnar | 3c43f03 | 2007-05-02 19:27:04 +0200 | [diff] [blame] | 72 | static inline void setup_apic_routing(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 74 | #ifdef CONFIG_X86_IO_APIC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | printk("Enabling APIC mode: %s. Using %d I/O APICs\n", |
| 76 | "Flat", nr_ioapics); |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 77 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | static inline int apicid_to_node(int logical_apicid) |
| 81 | { |
Yinghai Lu | f47f9d5 | 2008-06-24 22:13:15 -0700 | [diff] [blame] | 82 | #ifdef CONFIG_SMP |
| 83 | return apicid_2_node[hard_smp_processor_id()]; |
| 84 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | return 0; |
Yinghai Lu | f47f9d5 | 2008-06-24 22:13:15 -0700 | [diff] [blame] | 86 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 88 | |
| 89 | static inline cpumask_t vector_allocation_domain(int cpu) |
| 90 | { |
| 91 | /* Careful. Some cpus do not strictly honor the set of cpus |
| 92 | * specified in the interrupt destination when using lowest |
| 93 | * priority interrupt delivery mode. |
| 94 | * |
| 95 | * In particular there was a hyperthreading cpu observed to |
| 96 | * deliver interrupts to the wrong hyperthread when only one |
| 97 | * hyperthread was specified in the interrupt desitination. |
| 98 | */ |
| 99 | cpumask_t domain = { { [0] = APIC_ALL_CPUS, } }; |
| 100 | return domain; |
| 101 | } |
Glauber de Oliveira Costa | f6bc402 | 2008-03-19 14:25:53 -0300 | [diff] [blame] | 102 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 104 | static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid) |
| 105 | { |
| 106 | return physid_isset(apicid, bitmap); |
| 107 | } |
| 108 | |
| 109 | static inline unsigned long check_apicid_present(int bit) |
| 110 | { |
| 111 | return physid_isset(bit, phys_cpu_present_map); |
| 112 | } |
| 113 | |
| 114 | static inline physid_mask_t ioapic_phys_id_map(physid_mask_t phys_map) |
| 115 | { |
| 116 | return phys_map; |
| 117 | } |
| 118 | |
| 119 | static inline int multi_timer_check(int apic, int irq) |
| 120 | { |
| 121 | return 0; |
| 122 | } |
| 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | /* Mapping from cpu number to logical apicid */ |
| 125 | static inline int cpu_to_logical_apicid(int cpu) |
| 126 | { |
| 127 | return 1 << cpu; |
| 128 | } |
| 129 | |
| 130 | static inline int cpu_present_to_apicid(int mps_cpu) |
| 131 | { |
Hugh Dickins | 5f46470 | 2008-04-30 16:17:46 +0100 | [diff] [blame] | 132 | if (mps_cpu < NR_CPUS && cpu_present(mps_cpu)) |
Glauber de Oliveira Costa | f6bc402 | 2008-03-19 14:25:53 -0300 | [diff] [blame] | 133 | return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | else |
| 135 | return BAD_APICID; |
| 136 | } |
| 137 | |
| 138 | static inline physid_mask_t apicid_to_cpu_present(int phys_apicid) |
| 139 | { |
| 140 | return physid_mask_of_physid(phys_apicid); |
| 141 | } |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | static inline void setup_portio_remap(void) |
| 144 | { |
| 145 | } |
| 146 | |
| 147 | static inline int check_phys_apicid_present(int boot_cpu_physical_apicid) |
| 148 | { |
| 149 | return physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map); |
| 150 | } |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | static inline void enable_apic_mode(void) |
| 153 | { |
| 154 | } |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 155 | #endif /* CONFIG_X86_LOCAL_APIC */ |
Vegard Nossum | 77ef50a | 2008-06-18 17:08:48 +0200 | [diff] [blame] | 156 | #endif /* ASM_X86__MACH_DEFAULT__MACH_APIC_H */ |