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