blob: c3b9dc6970c95726a3adaafe5502334b9d64c68c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_MACH_APIC_H
2#define __ASM_MACH_APIC_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
Glauber de Oliveira Costacbe879f2008-03-19 14:25:19 -03004#define xapic_phys_to_log_apicid(cpu) (per_cpu(x86_bios_cpu_apicid, cpu))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#define esr_disable (1)
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007static inline int apic_id_registered(void)
8{
9 return (1);
10}
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012/* Round robin the irqs amoung the online cpus */
13static inline cpumask_t target_cpus(void)
14{
15 static unsigned long cpu = NR_CPUS;
16 do {
17 if (cpu >= NR_CPUS)
18 cpu = first_cpu(cpu_online_map);
19 else
20 cpu = next_cpu(cpu, cpu_online_map);
21 } while (cpu >= NR_CPUS);
22 return cpumask_of_cpu(cpu);
23}
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Ashok Raj1855a2c2006-01-06 00:12:08 -080025#undef APIC_DEST_LOGICAL
26#define APIC_DEST_LOGICAL 0
27#define TARGET_CPUS (target_cpus())
28#define APIC_DFR_VALUE (APIC_DFR_FLAT)
29#define INT_DELIVERY_MODE (dest_Fixed)
30#define INT_DEST_MODE (0) /* phys delivery to target proc */
31#define NO_BALANCE_IRQ (0)
32#define WAKE_SECONDARY_VIA_INIT
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid)
36{
Ashok Raj1855a2c2006-01-06 00:12:08 -080037 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
Ashok Raj1855a2c2006-01-06 00:12:08 -080040static inline unsigned long check_apicid_present(int bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
Ashok Raj1855a2c2006-01-06 00:12:08 -080042 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
Ashok Raj1855a2c2006-01-06 00:12:08 -080045static inline unsigned long calculate_ldr(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
Ashok Raj1855a2c2006-01-06 00:12:08 -080047 unsigned long val, id;
48 val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
49 id = xapic_phys_to_log_apicid(cpu);
50 val |= SET_APIC_LOGICAL_ID(id);
51 return val;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
54/*
55 * Set up the logical destination ID.
56 *
57 * Intel recommends to set DFR, LDR and TPR before enabling
58 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
59 * document number 292116). So here it goes...
60 */
61static inline void init_apic_ldr(void)
62{
63 unsigned long val;
Ashok Raj1855a2c2006-01-06 00:12:08 -080064 int cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +010066 apic_write(APIC_DFR, APIC_DFR_VALUE);
Ashok Raj1855a2c2006-01-06 00:12:08 -080067 val = calculate_ldr(cpu);
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +010068 apic_write(APIC_LDR, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
Ingo Molnar3c43f032007-05-02 19:27:04 +020071static inline void setup_apic_routing(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
73 printk("Enabling APIC mode: %s. Using %d I/O APICs\n",
Ashok Raj1855a2c2006-01-06 00:12:08 -080074 "Physflat", nr_ioapics);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
77static inline int multi_timer_check(int apic, int irq)
78{
Ashok Raj1855a2c2006-01-06 00:12:08 -080079 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
82static inline int apicid_to_node(int logical_apicid)
83{
Yinghai Luf47f9d52008-06-24 22:13:15 -070084 return apicid_2_node[hard_smp_processor_id()];
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static inline int cpu_present_to_apicid(int mps_cpu)
88{
89 if (mps_cpu < NR_CPUS)
Glauber de Oliveira Costacbe879f2008-03-19 14:25:19 -030090 return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
Ashok Raj1855a2c2006-01-06 00:12:08 -080091
92 return BAD_APICID;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94
95static inline physid_mask_t apicid_to_cpu_present(int phys_apicid)
96{
97 return physid_mask_of_physid(phys_apicid);
98}
99
100extern u8 cpu_2_logical_apicid[];
101/* Mapping from cpu number to logical apicid */
102static inline int cpu_to_logical_apicid(int cpu)
103{
Ashok Raj1855a2c2006-01-06 00:12:08 -0800104 if (cpu >= NR_CPUS)
105 return BAD_APICID;
106 return cpu_physical_id(cpu);
107}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109static inline physid_mask_t ioapic_phys_id_map(physid_mask_t phys_map)
110{
111 /* For clustered we don't have a good way to do this yet - hack */
Ashok Raj1855a2c2006-01-06 00:12:08 -0800112 return physids_promote(0xFFL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115static inline void setup_portio_remap(void)
116{
117}
118
119static inline void enable_apic_mode(void)
120{
121}
122
123static inline int check_phys_apicid_present(int boot_cpu_physical_apicid)
124{
125 return (1);
126}
127
128/* As we are using single CPU as destination, pick only one CPU here */
129static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
130{
131 int cpu;
132 int apicid;
133
134 cpu = first_cpu(cpumask);
135 apicid = cpu_to_logical_apicid(cpu);
136 return apicid;
137}
138
139static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
140{
141 return cpuid_apic >> index_msb;
142}
143
144#endif /* __ASM_MACH_APIC_H */