blob: 6cb3a467e0673c031c6e39b675481466a0c7531a [file] [log] [blame]
H. Peter Anvin05e4d312008-10-23 00:01:39 -07001#ifndef _ASM_X86_MACH_DEFAULT_MACH_APIC_H
2#define _ASM_X86_MACH_DEFAULT_MACH_APIC_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
Glauber Costadd46e3c2008-03-25 18:10:46 -03004#ifdef CONFIG_X86_LOCAL_APIC
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <mach_apicdef.h>
7#include <asm/smp.h>
8
9#define APIC_DFR_VALUE (APIC_DFR_FLAT)
10
11static 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 Torvalds1da177e2005-04-16 15:20:36 -070019
20#define NO_BALANCE_IRQ (0)
21#define esr_disable (0)
22
Glauber Costadd46e3c2008-03-25 18:10:46 -030023#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 Luf910a9d2008-07-12 01:01:20 -070033#define read_apic_id() (GET_APIC_ID(apic_read(APIC_ID)))
Suresh Siddhacff73a62008-07-10 11:16:53 -070034#define send_IPI_self (genapic->send_IPI_self)
Yinghai Lu54ac14a2008-11-17 15:19:53 -080035#define wakeup_secondary_cpu (genapic->wakeup_cpu)
Glauber Costadd46e3c2008-03-25 18:10:46 -030036extern void setup_apic_routing(void);
37#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define INT_DELIVERY_MODE dest_LowestPrio
39#define INT_DEST_MODE 1 /* logical delivery broadcast to all procs */
Glauber Costadd46e3c2008-03-25 18:10:46 -030040#define TARGET_CPUS (target_cpus())
Yinghai Lu54ac14a2008-11-17 15:19:53 -080041#define wakeup_secondary_cpu wakeup_secondary_cpu_via_init
Linus Torvalds1da177e2005-04-16 15:20:36 -070042/*
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 */
49static inline void init_apic_ldr(void)
50{
51 unsigned long val;
52
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +010053 apic_write(APIC_DFR, APIC_DFR_VALUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
55 val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +010056 apic_write(APIC_LDR, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
Glauber Costadd46e3c2008-03-25 18:10:46 -030059static inline int apic_id_registered(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Yinghai Lu4c9961d2008-07-11 18:44:16 -070061 return physid_isset(read_apic_id(), phys_cpu_present_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
Glauber Costadd46e3c2008-03-25 18:10:46 -030064static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
65{
66 return cpus_addr(cpumask)[0];
67}
68
69static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
70{
71 return cpuid_apic >> index_msb;
72}
73
Ingo Molnar3c43f032007-05-02 19:27:04 +020074static inline void setup_apic_routing(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Alexey Starikovskiy61048c62008-04-04 23:41:07 +040076#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 printk("Enabling APIC mode: %s. Using %d I/O APICs\n",
78 "Flat", nr_ioapics);
Alexey Starikovskiy61048c62008-04-04 23:41:07 +040079#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082static inline int apicid_to_node(int logical_apicid)
83{
Yinghai Luf47f9d52008-06-24 22:13:15 -070084#ifdef CONFIG_SMP
85 return apicid_2_node[hard_smp_processor_id()];
86#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 return 0;
Yinghai Luf47f9d52008-06-24 22:13:15 -070088#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
Yinghai Lu497c9a12008-08-19 20:50:28 -070090
91static inline cpumask_t vector_allocation_domain(int cpu)
92{
93 /* Careful. Some cpus do not strictly honor the set of cpus
94 * specified in the interrupt destination when using lowest
95 * priority interrupt delivery mode.
96 *
97 * In particular there was a hyperthreading cpu observed to
98 * deliver interrupts to the wrong hyperthread when only one
99 * hyperthread was specified in the interrupt desitination.
100 */
101 cpumask_t domain = { { [0] = APIC_ALL_CPUS, } };
102 return domain;
103}
Glauber de Oliveira Costaf6bc4022008-03-19 14:25:53 -0300104#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Glauber Costadd46e3c2008-03-25 18:10:46 -0300106static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid)
107{
108 return physid_isset(apicid, bitmap);
109}
110
111static inline unsigned long check_apicid_present(int bit)
112{
113 return physid_isset(bit, phys_cpu_present_map);
114}
115
116static inline physid_mask_t ioapic_phys_id_map(physid_mask_t phys_map)
117{
118 return phys_map;
119}
120
121static inline int multi_timer_check(int apic, int irq)
122{
123 return 0;
124}
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126/* Mapping from cpu number to logical apicid */
127static inline int cpu_to_logical_apicid(int cpu)
128{
129 return 1 << cpu;
130}
131
132static inline int cpu_present_to_apicid(int mps_cpu)
133{
Hugh Dickins5f464702008-04-30 16:17:46 +0100134 if (mps_cpu < NR_CPUS && cpu_present(mps_cpu))
Glauber de Oliveira Costaf6bc4022008-03-19 14:25:53 -0300135 return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 else
137 return BAD_APICID;
138}
139
140static inline physid_mask_t apicid_to_cpu_present(int phys_apicid)
141{
142 return physid_mask_of_physid(phys_apicid);
143}
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145static inline void setup_portio_remap(void)
146{
147}
148
149static inline int check_phys_apicid_present(int boot_cpu_physical_apicid)
150{
151 return physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map);
152}
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154static inline void enable_apic_mode(void)
155{
156}
Glauber Costadd46e3c2008-03-25 18:10:46 -0300157#endif /* CONFIG_X86_LOCAL_APIC */
H. Peter Anvin05e4d312008-10-23 00:01:39 -0700158#endif /* _ASM_X86_MACH_DEFAULT_MACH_APIC_H */