Yinghai Lu | 1176fa9 | 2008-07-25 02:17:21 -0700 | [diff] [blame] | 1 | #ifndef __ASM_MACH_APIC_H |
| 2 | #define __ASM_MACH_APIC_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | |
Glauber de Oliveira Costa | cbe879f | 2008-03-19 14:25:19 -0300 | [diff] [blame] | 4 | #define xapic_phys_to_log_apicid(cpu) (per_cpu(x86_bios_cpu_apicid, cpu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | |
Ingo Molnar | 7ed248d | 2009-01-28 03:43:47 +0100 | [diff] [blame] | 6 | static inline int bigsmp_apic_id_registered(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | { |
Ingo Molnar | 7ed248d | 2009-01-28 03:43:47 +0100 | [diff] [blame] | 8 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | } |
| 10 | |
Ingo Molnar | 0a9cc20 | 2009-01-28 04:30:40 +0100 | [diff] [blame] | 11 | static inline const cpumask_t *bigsmp_target_cpus(void) |
Yinghai Lu | 1176fa9 | 2008-07-25 02:17:21 -0700 | [diff] [blame] | 12 | { |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 13 | #ifdef CONFIG_SMP |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 14 | return &cpu_online_map; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 15 | #else |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 16 | return &cpumask_of_cpu(0); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 17 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Ashok Raj | 1855a2c | 2006-01-06 00:12:08 -0800 | [diff] [blame] | 20 | #define APIC_DFR_VALUE (APIC_DFR_FLAT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Ingo Molnar | d1d7cae | 2009-01-28 05:41:42 +0100 | [diff] [blame] | 22 | static inline unsigned long |
| 23 | bigsmp_check_apicid_used(physid_mask_t bitmap, int apicid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | { |
Ingo Molnar | d1d7cae | 2009-01-28 05:41:42 +0100 | [diff] [blame] | 25 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Ingo Molnar | d1d7cae | 2009-01-28 05:41:42 +0100 | [diff] [blame] | 28 | static inline unsigned long bigsmp_check_apicid_present(int bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | { |
Ingo Molnar | d1d7cae | 2009-01-28 05:41:42 +0100 | [diff] [blame] | 30 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Ashok Raj | 1855a2c | 2006-01-06 00:12:08 -0800 | [diff] [blame] | 33 | static inline unsigned long calculate_ldr(int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
Ashok Raj | 1855a2c | 2006-01-06 00:12:08 -0800 | [diff] [blame] | 35 | unsigned long val, id; |
| 36 | val = apic_read(APIC_LDR) & ~APIC_LDR_MASK; |
| 37 | id = xapic_phys_to_log_apicid(cpu); |
| 38 | val |= SET_APIC_LOGICAL_ID(id); |
| 39 | return val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /* |
| 43 | * Set up the logical destination ID. |
| 44 | * |
| 45 | * Intel recommends to set DFR, LDR and TPR before enabling |
| 46 | * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel |
| 47 | * document number 292116). So here it goes... |
| 48 | */ |
| 49 | static inline void init_apic_ldr(void) |
| 50 | { |
| 51 | unsigned long val; |
Ashok Raj | 1855a2c | 2006-01-06 00:12:08 -0800 | [diff] [blame] | 52 | int cpu = smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 54 | apic_write(APIC_DFR, APIC_DFR_VALUE); |
Ashok Raj | 1855a2c | 2006-01-06 00:12:08 -0800 | [diff] [blame] | 55 | val = calculate_ldr(cpu); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 56 | apic_write(APIC_LDR, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Ingo Molnar | 3c43f03 | 2007-05-02 19:27:04 +0200 | [diff] [blame] | 59 | static inline void setup_apic_routing(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
| 61 | printk("Enabling APIC mode: %s. Using %d I/O APICs\n", |
Ashok Raj | 1855a2c | 2006-01-06 00:12:08 -0800 | [diff] [blame] | 62 | "Physflat", nr_ioapics); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static inline int multi_timer_check(int apic, int irq) |
| 66 | { |
Ashok Raj | 1855a2c | 2006-01-06 00:12:08 -0800 | [diff] [blame] | 67 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static inline int apicid_to_node(int logical_apicid) |
| 71 | { |
Yinghai Lu | f47f9d5 | 2008-06-24 22:13:15 -0700 | [diff] [blame] | 72 | return apicid_2_node[hard_smp_processor_id()]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | static inline int cpu_present_to_apicid(int mps_cpu) |
| 76 | { |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 77 | if (mps_cpu < nr_cpu_ids) |
Glauber de Oliveira Costa | cbe879f | 2008-03-19 14:25:19 -0300 | [diff] [blame] | 78 | return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu); |
Ashok Raj | 1855a2c | 2006-01-06 00:12:08 -0800 | [diff] [blame] | 79 | |
| 80 | return BAD_APICID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static inline physid_mask_t apicid_to_cpu_present(int phys_apicid) |
| 84 | { |
| 85 | return physid_mask_of_physid(phys_apicid); |
| 86 | } |
| 87 | |
| 88 | extern u8 cpu_2_logical_apicid[]; |
| 89 | /* Mapping from cpu number to logical apicid */ |
| 90 | static inline int cpu_to_logical_apicid(int cpu) |
| 91 | { |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 92 | if (cpu >= nr_cpu_ids) |
Ashok Raj | 1855a2c | 2006-01-06 00:12:08 -0800 | [diff] [blame] | 93 | return BAD_APICID; |
| 94 | return cpu_physical_id(cpu); |
| 95 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | static inline physid_mask_t ioapic_phys_id_map(physid_mask_t phys_map) |
| 98 | { |
| 99 | /* For clustered we don't have a good way to do this yet - hack */ |
Ashok Raj | 1855a2c | 2006-01-06 00:12:08 -0800 | [diff] [blame] | 100 | return physids_promote(0xFFL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | static inline void setup_portio_remap(void) |
| 104 | { |
| 105 | } |
| 106 | |
| 107 | static inline void enable_apic_mode(void) |
| 108 | { |
| 109 | } |
| 110 | |
| 111 | static inline int check_phys_apicid_present(int boot_cpu_physical_apicid) |
| 112 | { |
| 113 | return (1); |
| 114 | } |
| 115 | |
| 116 | /* As we are using single CPU as destination, pick only one CPU here */ |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 117 | static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
| 119 | int cpu; |
| 120 | int apicid; |
| 121 | |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 122 | cpu = first_cpu(*cpumask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | apicid = cpu_to_logical_apicid(cpu); |
| 124 | return apicid; |
| 125 | } |
| 126 | |
Mike Travis | 6eeb7c5 | 2008-12-16 17:33:55 -0800 | [diff] [blame] | 127 | static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *cpumask, |
| 128 | const struct cpumask *andmask) |
Mike Travis | 95d313c | 2008-12-16 17:33:54 -0800 | [diff] [blame] | 129 | { |
| 130 | int cpu; |
| 131 | |
| 132 | /* |
| 133 | * We're using fixed IRQ delivery, can only return one phys APIC ID. |
| 134 | * May as well be the first. |
| 135 | */ |
Mike Travis | a775a38 | 2008-12-17 15:21:39 -0800 | [diff] [blame] | 136 | for_each_cpu_and(cpu, cpumask, andmask) |
| 137 | if (cpumask_test_cpu(cpu, cpu_online_mask)) |
| 138 | break; |
Mike Travis | 6eeb7c5 | 2008-12-16 17:33:55 -0800 | [diff] [blame] | 139 | if (cpu < nr_cpu_ids) |
| 140 | return cpu_to_logical_apicid(cpu); |
Mike Travis | 95d313c | 2008-12-16 17:33:54 -0800 | [diff] [blame] | 141 | |
| 142 | return BAD_APICID; |
| 143 | } |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb) |
| 146 | { |
| 147 | return cpuid_apic >> index_msb; |
| 148 | } |
| 149 | |
Yinghai Lu | 1176fa9 | 2008-07-25 02:17:21 -0700 | [diff] [blame] | 150 | #endif /* __ASM_MACH_APIC_H */ |