H. Peter Anvin | 05e4d31 | 2008-10-23 00:01:39 -0700 | [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 | |
Ingo Molnar | 0a9cc20 | 2009-01-28 04:30:40 +0100 | [diff] [blame] | 11 | static inline const struct cpumask *default_target_cpus(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | { |
| 13 | #ifdef CONFIG_SMP |
Mike Travis | bcda016 | 2008-12-16 17:33:59 -0800 | [diff] [blame] | 14 | return cpu_online_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #else |
Mike Travis | bcda016 | 2008-12-16 17:33:59 -0800 | [diff] [blame] | 16 | return cpumask_of(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #endif |
| 18 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 20 | #ifdef CONFIG_X86_64 |
| 21 | #include <asm/genapic.h> |
Ingo Molnar | c8d46cf | 2009-01-28 00:14:11 +0100 | [diff] [blame] | 22 | #define cpu_mask_to_apicid (apic->cpu_mask_to_apicid) |
| 23 | #define cpu_mask_to_apicid_and (apic->cpu_mask_to_apicid_and) |
| 24 | #define phys_pkg_id (apic->phys_pkg_id) |
Yinghai Lu | f910a9d | 2008-07-12 01:01:20 -0700 | [diff] [blame] | 25 | #define read_apic_id() (GET_APIC_ID(apic_read(APIC_ID))) |
Ingo Molnar | c8d46cf | 2009-01-28 00:14:11 +0100 | [diff] [blame] | 26 | #define send_IPI_self (apic->send_IPI_self) |
| 27 | #define wakeup_secondary_cpu (apic->wakeup_cpu) |
Ingo Molnar | 72ce016 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 28 | extern void default_setup_apic_routing(void); |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 29 | #else |
Yinghai Lu | 54ac14a | 2008-11-17 15:19:53 -0800 | [diff] [blame] | 30 | #define wakeup_secondary_cpu wakeup_secondary_cpu_via_init |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | /* |
| 32 | * Set up the logical destination ID. |
| 33 | * |
| 34 | * Intel recommends to set DFR, LDR and TPR before enabling |
| 35 | * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel |
| 36 | * document number 292116). So here it goes... |
| 37 | */ |
Ingo Molnar | a5c4329 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 38 | static inline void default_init_apic_ldr(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
| 40 | unsigned long val; |
| 41 | |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 42 | apic_write(APIC_DFR, APIC_DFR_VALUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | val = apic_read(APIC_LDR) & ~APIC_LDR_MASK; |
| 44 | val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id()); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 45 | apic_write(APIC_LDR, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Ingo Molnar | 7ed248d | 2009-01-28 03:43:47 +0100 | [diff] [blame] | 48 | static inline int default_apic_id_registered(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 50 | return physid_isset(read_apic_id(), phys_cpu_present_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Mike Travis | bcda016 | 2008-12-16 17:33:59 -0800 | [diff] [blame] | 53 | static inline unsigned int cpu_mask_to_apicid(const struct cpumask *cpumask) |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 54 | { |
Mike Travis | bcda016 | 2008-12-16 17:33:59 -0800 | [diff] [blame] | 55 | return cpumask_bits(cpumask)[0]; |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 56 | } |
| 57 | |
Mike Travis | 6eeb7c5 | 2008-12-16 17:33:55 -0800 | [diff] [blame] | 58 | static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *cpumask, |
| 59 | const struct cpumask *andmask) |
Mike Travis | 95d313c | 2008-12-16 17:33:54 -0800 | [diff] [blame] | 60 | { |
Mike Travis | 6eeb7c5 | 2008-12-16 17:33:55 -0800 | [diff] [blame] | 61 | unsigned long mask1 = cpumask_bits(cpumask)[0]; |
| 62 | unsigned long mask2 = cpumask_bits(andmask)[0]; |
Mike Travis | a775a38 | 2008-12-17 15:21:39 -0800 | [diff] [blame] | 63 | unsigned long mask3 = cpumask_bits(cpu_online_mask)[0]; |
Mike Travis | 95d313c | 2008-12-16 17:33:54 -0800 | [diff] [blame] | 64 | |
Mike Travis | a775a38 | 2008-12-17 15:21:39 -0800 | [diff] [blame] | 65 | return (unsigned int)(mask1 & mask2 & mask3); |
Mike Travis | 95d313c | 2008-12-16 17:33:54 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 68 | static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb) |
| 69 | { |
| 70 | return cpuid_apic >> index_msb; |
| 71 | } |
| 72 | |
Ingo Molnar | 72ce016 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 73 | static inline void default_setup_apic_routing(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 75 | #ifdef CONFIG_X86_IO_APIC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | printk("Enabling APIC mode: %s. Using %d I/O APICs\n", |
| 77 | "Flat", nr_ioapics); |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 78 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Ingo Molnar | 3f57a31 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 81 | static inline int default_apicid_to_node(int logical_apicid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
Yinghai Lu | f47f9d5 | 2008-06-24 22:13:15 -0700 | [diff] [blame] | 83 | #ifdef CONFIG_SMP |
| 84 | return apicid_2_node[hard_smp_processor_id()]; |
| 85 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | return 0; |
Yinghai Lu | f47f9d5 | 2008-06-24 22:13:15 -0700 | [diff] [blame] | 87 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 89 | |
Glauber de Oliveira Costa | f6bc402 | 2008-03-19 14:25:53 -0300 | [diff] [blame] | 90 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Ingo Molnar | d1d7cae | 2009-01-28 05:41:42 +0100 | [diff] [blame] | 92 | static inline unsigned long default_check_apicid_used(physid_mask_t bitmap, int apicid) |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 93 | { |
| 94 | return physid_isset(apicid, bitmap); |
| 95 | } |
| 96 | |
Ingo Molnar | d1d7cae | 2009-01-28 05:41:42 +0100 | [diff] [blame] | 97 | static inline unsigned long default_check_apicid_present(int bit) |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 98 | { |
| 99 | return physid_isset(bit, phys_cpu_present_map); |
| 100 | } |
| 101 | |
Ingo Molnar | d190cb8 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 102 | static inline physid_mask_t default_ioapic_phys_id_map(physid_mask_t phys_map) |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 103 | { |
| 104 | return phys_map; |
| 105 | } |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | /* Mapping from cpu number to logical apicid */ |
Ingo Molnar | 5257c51 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 108 | static inline int default_cpu_to_logical_apicid(int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
| 110 | return 1 << cpu; |
| 111 | } |
| 112 | |
Ingo Molnar | a21769a4 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 113 | static inline int __default_cpu_present_to_apicid(int mps_cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 115 | if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu)) |
Glauber de Oliveira Costa | f6bc402 | 2008-03-19 14:25:53 -0300 | [diff] [blame] | 116 | return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | else |
| 118 | return BAD_APICID; |
| 119 | } |
| 120 | |
Ingo Molnar | a21769a4 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 121 | #ifdef CONFIG_X86_32 |
| 122 | static inline int default_cpu_present_to_apicid(int mps_cpu) |
| 123 | { |
| 124 | return __default_cpu_present_to_apicid(mps_cpu); |
| 125 | } |
| 126 | #else |
| 127 | extern int default_cpu_present_to_apicid(int mps_cpu); |
| 128 | #endif |
| 129 | |
Ingo Molnar | 8058714 | 2009-01-28 06:50:47 +0100 | [diff] [blame^] | 130 | static inline physid_mask_t default_apicid_to_cpu_present(int phys_apicid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
| 132 | return physid_mask_of_physid(phys_apicid); |
| 133 | } |
| 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | static inline void setup_portio_remap(void) |
| 136 | { |
| 137 | } |
| 138 | |
| 139 | static inline int check_phys_apicid_present(int boot_cpu_physical_apicid) |
| 140 | { |
| 141 | return physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map); |
| 142 | } |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | static inline void enable_apic_mode(void) |
| 145 | { |
| 146 | } |
Glauber Costa | dd46e3c | 2008-03-25 18:10:46 -0300 | [diff] [blame] | 147 | #endif /* CONFIG_X86_LOCAL_APIC */ |
H. Peter Anvin | 05e4d31 | 2008-10-23 00:01:39 -0700 | [diff] [blame] | 148 | #endif /* _ASM_X86_MACH_DEFAULT_MACH_APIC_H */ |