Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 1 | #ifndef _ASM_X86_GENAPIC_H |
| 2 | #define _ASM_X86_GENAPIC_H |
| 3 | |
| 4 | #include <linux/cpumask.h> |
| 5 | |
Ingo Molnar | 505deeb | 2009-01-27 23:23:22 +0100 | [diff] [blame] | 6 | #include <asm/mpspec.h> |
| 7 | #include <asm/atomic.h> |
| 8 | |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 9 | /* |
| 10 | * Copyright 2004 James Cleverdon, IBM. |
| 11 | * Subject to the GNU Public License, v.2 |
| 12 | * |
| 13 | * Generic APIC sub-arch data struct. |
| 14 | * |
| 15 | * Hacked for x86-64 by James Cleverdon from i386 architecture code by |
| 16 | * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and |
| 17 | * James Cleverdon. |
| 18 | */ |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 19 | struct genapic { |
| 20 | char *name; |
| 21 | |
| 22 | int (*probe)(void); |
| 23 | int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id); |
| 24 | int (*apic_id_registered)(void); |
| 25 | |
Ingo Molnar | f8987a1 | 2009-01-28 04:02:31 +0100 | [diff] [blame] | 26 | u32 irq_delivery_mode; |
| 27 | u32 irq_dest_mode; |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 28 | |
| 29 | const struct cpumask *(*target_cpus)(void); |
| 30 | |
Ingo Molnar | 08125d3 | 2009-01-28 05:08:44 +0100 | [diff] [blame] | 31 | int disable_esr; |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 32 | |
Ingo Molnar | bdb1a9b | 2009-01-28 05:29:25 +0100 | [diff] [blame] | 33 | int dest_logical; |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 34 | unsigned long (*check_apicid_used)(physid_mask_t bitmap, int apicid); |
| 35 | unsigned long (*check_apicid_present)(int apicid); |
| 36 | |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 37 | void (*vector_allocation_domain)(int cpu, struct cpumask *retmask); |
| 38 | void (*init_apic_ldr)(void); |
| 39 | |
| 40 | physid_mask_t (*ioapic_phys_id_map)(physid_mask_t map); |
| 41 | |
| 42 | void (*setup_apic_routing)(void); |
| 43 | int (*multi_timer_check)(int apic, int irq); |
| 44 | int (*apicid_to_node)(int logical_apicid); |
| 45 | int (*cpu_to_logical_apicid)(int cpu); |
| 46 | int (*cpu_present_to_apicid)(int mps_cpu); |
| 47 | physid_mask_t (*apicid_to_cpu_present)(int phys_apicid); |
| 48 | void (*setup_portio_remap)(void); |
| 49 | int (*check_phys_apicid_present)(int boot_cpu_physical_apicid); |
| 50 | void (*enable_apic_mode)(void); |
Ingo Molnar | d4c9a9f | 2009-01-28 13:31:22 +0100 | [diff] [blame] | 51 | int (*phys_pkg_id)(int cpuid_apic, int index_msb); |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * When one of the next two hooks returns 1 the genapic |
| 55 | * is switched to this. Essentially they are additional |
| 56 | * probe functions: |
| 57 | */ |
Ingo Molnar | 5f83640 | 2009-01-28 13:47:42 +0100 | [diff] [blame] | 58 | int (*mps_oem_check)(struct mpc_table *mpc, char *oem, char *productid); |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 59 | |
| 60 | unsigned int (*get_apic_id)(unsigned long x); |
| 61 | unsigned long (*set_apic_id)(unsigned int id); |
| 62 | unsigned long apic_id_mask; |
| 63 | |
| 64 | unsigned int (*cpu_mask_to_apicid)(const struct cpumask *cpumask); |
| 65 | unsigned int (*cpu_mask_to_apicid_and)(const struct cpumask *cpumask, |
| 66 | const struct cpumask *andmask); |
| 67 | |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 68 | /* ipi */ |
| 69 | void (*send_IPI_mask)(const struct cpumask *mask, int vector); |
| 70 | void (*send_IPI_mask_allbutself)(const struct cpumask *mask, |
| 71 | int vector); |
| 72 | void (*send_IPI_allbutself)(int vector); |
| 73 | void (*send_IPI_all)(int vector); |
| 74 | void (*send_IPI_self)(int vector); |
Ingo Molnar | 6781d94 | 2009-01-27 23:54:23 +0100 | [diff] [blame] | 75 | |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 76 | /* wakeup_secondary_cpu */ |
| 77 | int (*wakeup_cpu)(int apicid, unsigned long start_eip); |
| 78 | |
| 79 | int trampoline_phys_low; |
| 80 | int trampoline_phys_high; |
Ingo Molnar | 505deeb | 2009-01-27 23:23:22 +0100 | [diff] [blame] | 81 | |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 82 | void (*wait_for_init_deassert)(atomic_t *deassert); |
| 83 | void (*smp_callin_clear_local_apic)(void); |
| 84 | void (*store_NMI_vector)(unsigned short *high, unsigned short *low); |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 85 | void (*inquire_remote_apic)(int apicid); |
| 86 | }; |
| 87 | |
Ingo Molnar | c8d46cf | 2009-01-28 00:14:11 +0100 | [diff] [blame] | 88 | extern struct genapic *apic; |
Ingo Molnar | ced733e | 2009-01-27 23:15:06 +0100 | [diff] [blame] | 89 | |
Ingo Molnar | abfa584 | 2009-01-28 16:15:16 +0100 | [diff] [blame] | 90 | /* |
| 91 | * Warm reset vector default position: |
| 92 | */ |
| 93 | #define DEFAULT_TRAMPOLINE_PHYS_LOW 0x467 |
| 94 | #define DEFAULT_TRAMPOLINE_PHYS_HIGH 0x469 |
| 95 | |
Ingo Molnar | 505deeb | 2009-01-27 23:23:22 +0100 | [diff] [blame] | 96 | #ifdef CONFIG_X86_32 |
Ingo Molnar | ced733e | 2009-01-27 23:15:06 +0100 | [diff] [blame] | 97 | extern void es7000_update_genapic_to_cluster(void); |
Ingo Molnar | 9a6801d | 2009-01-28 03:18:13 +0100 | [diff] [blame] | 98 | #else |
Ingo Molnar | ced733e | 2009-01-27 23:15:06 +0100 | [diff] [blame] | 99 | extern struct genapic apic_flat; |
| 100 | extern struct genapic apic_physflat; |
| 101 | extern struct genapic apic_x2apic_cluster; |
| 102 | extern struct genapic apic_x2apic_phys; |
Ingo Molnar | 306db03 | 2009-01-28 03:43:47 +0100 | [diff] [blame] | 103 | extern int default_acpi_madt_oem_check(char *, char *); |
Ingo Molnar | ced733e | 2009-01-27 23:15:06 +0100 | [diff] [blame] | 104 | |
| 105 | extern void apic_send_IPI_self(int vector); |
| 106 | |
| 107 | extern struct genapic apic_x2apic_uv_x; |
| 108 | DECLARE_PER_CPU(int, x2apic_extra_bits); |
| 109 | |
Ingo Molnar | 72ce016 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 110 | extern void default_setup_apic_routing(void); |
Ingo Molnar | a21769a4 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 111 | |
| 112 | extern int default_cpu_present_to_apicid(int mps_cpu); |
Ingo Molnar | a27a621 | 2009-01-28 12:43:18 +0100 | [diff] [blame] | 113 | extern int default_check_phys_apicid_present(int boot_cpu_physical_apicid); |
Ingo Molnar | 9a6801d | 2009-01-28 03:18:13 +0100 | [diff] [blame] | 114 | #endif |
Ingo Molnar | ced733e | 2009-01-27 23:15:06 +0100 | [diff] [blame] | 115 | |
Ingo Molnar | 0939e4f | 2009-01-28 17:16:25 +0100 | [diff] [blame] | 116 | static inline void default_wait_for_init_deassert(atomic_t *deassert) |
| 117 | { |
| 118 | while (!atomic_read(deassert)) |
| 119 | cpu_relax(); |
| 120 | return; |
| 121 | } |
| 122 | |
Ingo Molnar | 1dcdd3d | 2009-01-28 17:55:37 +0100 | [diff] [blame] | 123 | extern void generic_bigsmp_probe(void); |
| 124 | |
| 125 | |
| 126 | #ifdef CONFIG_X86_LOCAL_APIC |
| 127 | |
| 128 | #include <asm/smp.h> |
| 129 | |
| 130 | #define APIC_DFR_VALUE (APIC_DFR_FLAT) |
| 131 | |
| 132 | static inline const struct cpumask *default_target_cpus(void) |
| 133 | { |
| 134 | #ifdef CONFIG_SMP |
| 135 | return cpu_online_mask; |
| 136 | #else |
| 137 | return cpumask_of(0); |
| 138 | #endif |
| 139 | } |
| 140 | |
| 141 | DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid); |
| 142 | |
| 143 | |
| 144 | static inline unsigned int read_apic_id(void) |
| 145 | { |
| 146 | unsigned int reg; |
| 147 | |
Suresh Siddha | 83d7aea | 2009-01-28 17:52:57 -0800 | [diff] [blame^] | 148 | reg = apic_read(APIC_ID); |
Ingo Molnar | 1dcdd3d | 2009-01-28 17:55:37 +0100 | [diff] [blame] | 149 | |
| 150 | return apic->get_apic_id(reg); |
| 151 | } |
| 152 | |
| 153 | #ifdef CONFIG_X86_64 |
| 154 | extern void default_setup_apic_routing(void); |
| 155 | #else |
| 156 | |
| 157 | /* |
| 158 | * Set up the logical destination ID. |
| 159 | * |
| 160 | * Intel recommends to set DFR, LDR and TPR before enabling |
| 161 | * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel |
| 162 | * document number 292116). So here it goes... |
| 163 | */ |
| 164 | extern void default_init_apic_ldr(void); |
| 165 | |
| 166 | static inline int default_apic_id_registered(void) |
| 167 | { |
| 168 | return physid_isset(read_apic_id(), phys_cpu_present_map); |
| 169 | } |
| 170 | |
| 171 | static inline unsigned int |
| 172 | default_cpu_mask_to_apicid(const struct cpumask *cpumask) |
| 173 | { |
| 174 | return cpumask_bits(cpumask)[0]; |
| 175 | } |
| 176 | |
| 177 | static inline unsigned int |
| 178 | default_cpu_mask_to_apicid_and(const struct cpumask *cpumask, |
| 179 | const struct cpumask *andmask) |
| 180 | { |
| 181 | unsigned long mask1 = cpumask_bits(cpumask)[0]; |
| 182 | unsigned long mask2 = cpumask_bits(andmask)[0]; |
| 183 | unsigned long mask3 = cpumask_bits(cpu_online_mask)[0]; |
| 184 | |
| 185 | return (unsigned int)(mask1 & mask2 & mask3); |
| 186 | } |
| 187 | |
| 188 | static inline int default_phys_pkg_id(int cpuid_apic, int index_msb) |
| 189 | { |
| 190 | return cpuid_apic >> index_msb; |
| 191 | } |
| 192 | |
| 193 | static inline void default_setup_apic_routing(void) |
| 194 | { |
| 195 | #ifdef CONFIG_X86_IO_APIC |
| 196 | printk("Enabling APIC mode: %s. Using %d I/O APICs\n", |
| 197 | "Flat", nr_ioapics); |
| 198 | #endif |
| 199 | } |
| 200 | |
| 201 | extern int default_apicid_to_node(int logical_apicid); |
| 202 | |
| 203 | #endif |
| 204 | |
| 205 | static inline unsigned long default_check_apicid_used(physid_mask_t bitmap, int apicid) |
| 206 | { |
| 207 | return physid_isset(apicid, bitmap); |
| 208 | } |
| 209 | |
| 210 | static inline unsigned long default_check_apicid_present(int bit) |
| 211 | { |
| 212 | return physid_isset(bit, phys_cpu_present_map); |
| 213 | } |
| 214 | |
| 215 | static inline physid_mask_t default_ioapic_phys_id_map(physid_mask_t phys_map) |
| 216 | { |
| 217 | return phys_map; |
| 218 | } |
| 219 | |
| 220 | /* Mapping from cpu number to logical apicid */ |
| 221 | static inline int default_cpu_to_logical_apicid(int cpu) |
| 222 | { |
| 223 | return 1 << cpu; |
| 224 | } |
| 225 | |
| 226 | static inline int __default_cpu_present_to_apicid(int mps_cpu) |
| 227 | { |
| 228 | if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu)) |
| 229 | return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu); |
| 230 | else |
| 231 | return BAD_APICID; |
| 232 | } |
| 233 | |
| 234 | static inline int |
| 235 | __default_check_phys_apicid_present(int boot_cpu_physical_apicid) |
| 236 | { |
| 237 | return physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map); |
| 238 | } |
| 239 | |
| 240 | #ifdef CONFIG_X86_32 |
| 241 | static inline int default_cpu_present_to_apicid(int mps_cpu) |
| 242 | { |
| 243 | return __default_cpu_present_to_apicid(mps_cpu); |
| 244 | } |
| 245 | |
| 246 | static inline int |
| 247 | default_check_phys_apicid_present(int boot_cpu_physical_apicid) |
| 248 | { |
| 249 | return __default_check_phys_apicid_present(boot_cpu_physical_apicid); |
| 250 | } |
| 251 | #else |
| 252 | extern int default_cpu_present_to_apicid(int mps_cpu); |
| 253 | extern int default_check_phys_apicid_present(int boot_cpu_physical_apicid); |
| 254 | #endif |
| 255 | |
| 256 | static inline physid_mask_t default_apicid_to_cpu_present(int phys_apicid) |
| 257 | { |
| 258 | return physid_mask_of_physid(phys_apicid); |
| 259 | } |
| 260 | |
| 261 | #endif /* CONFIG_X86_LOCAL_APIC */ |
Ingo Molnar | ef7471b | 2009-01-27 23:12:02 +0100 | [diff] [blame] | 262 | #endif /* _ASM_X86_GENAPIC_64_H */ |