blob: 380f0b4f17edfcf5c1e1440baed7231e07cdb684 [file] [log] [blame]
Yinghai Luc7e79642008-07-25 02:17:33 -07001#ifndef __ASM_ES7000_APIC_H
2#define __ASM_ES7000_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
7static inline int apic_id_registered(void)
8{
9 return (1);
10}
11
12static inline cpumask_t target_cpus(void)
Yinghai Luc7e79642008-07-25 02:17:33 -070013{
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#if defined CONFIG_ES7000_CLUSTERED_APIC
15 return CPU_MASK_ALL;
16#else
17 return cpumask_of_cpu(smp_processor_id());
18#endif
19}
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#if defined CONFIG_ES7000_CLUSTERED_APIC
22#define APIC_DFR_VALUE (APIC_DFR_CLUSTER)
23#define INT_DELIVERY_MODE (dest_LowestPrio)
24#define INT_DEST_MODE (1) /* logical delivery broadcast to all procs */
Yinghai Luc7e79642008-07-25 02:17:33 -070025#define NO_BALANCE_IRQ (1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#undef WAKE_SECONDARY_VIA_INIT
27#define WAKE_SECONDARY_VIA_MIP
28#else
29#define APIC_DFR_VALUE (APIC_DFR_FLAT)
30#define INT_DELIVERY_MODE (dest_Fixed)
31#define INT_DEST_MODE (0) /* phys delivery to target procs */
Yinghai Luc7e79642008-07-25 02:17:33 -070032#define NO_BALANCE_IRQ (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#undef APIC_DEST_LOGICAL
34#define APIC_DEST_LOGICAL 0x0
35#define WAKE_SECONDARY_VIA_INIT
36#endif
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid)
Yinghai Luc7e79642008-07-25 02:17:33 -070039{
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 return 0;
Yinghai Luc7e79642008-07-25 02:17:33 -070041}
42static inline unsigned long check_apicid_present(int bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44 return physid_isset(bit, phys_cpu_present_map);
45}
46
47#define apicid_cluster(apicid) (apicid & 0xF0)
48
49static inline unsigned long calculate_ldr(int cpu)
50{
51 unsigned long id;
52 id = xapic_phys_to_log_apicid(cpu);
53 return (SET_APIC_LOGICAL_ID(id));
54}
55
56/*
57 * Set up the logical destination ID.
58 *
59 * Intel recommends to set DFR, LdR and TPR before enabling
60 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
61 * document number 292116). So here it goes...
62 */
63static inline void init_apic_ldr(void)
64{
65 unsigned long val;
66 int cpu = smp_processor_id();
67
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +010068 apic_write(APIC_DFR, APIC_DFR_VALUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 val = calculate_ldr(cpu);
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +010070 apic_write(APIC_LDR, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Vivek Goyal071922c2007-07-06 02:39:55 -070073#ifndef CONFIG_X86_GENERICARCH
74extern void enable_apic_mode(void);
75#endif
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int apic_version [MAX_APICS];
Ingo Molnar3c43f032007-05-02 19:27:04 +020078static inline void setup_apic_routing(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Glauber de Oliveira Costacbe879f2008-03-19 14:25:19 -030080 int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
Yinghai Luc7e79642008-07-25 02:17:33 -070082 (apic_version[apic] == 0x14) ?
Yinghai Lu497c9a12008-08-19 20:50:28 -070083 "Physical Cluster" : "Logical Cluster", nr_ioapics, cpus_addr(target_cpus())[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
86static inline int multi_timer_check(int apic, int irq)
87{
88 return 0;
89}
90
91static inline int apicid_to_node(int logical_apicid)
92{
93 return 0;
94}
95
96
97static inline int cpu_present_to_apicid(int mps_cpu)
98{
99 if (!mps_cpu)
100 return boot_cpu_physical_apicid;
101 else if (mps_cpu < NR_CPUS)
Glauber de Oliveira Costacbe879f2008-03-19 14:25:19 -0300102 return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 else
104 return BAD_APICID;
105}
106
107static inline physid_mask_t apicid_to_cpu_present(int phys_apicid)
108{
109 static int id = 0;
110 physid_mask_t mask;
111 mask = physid_mask_of_physid(id);
112 ++id;
113 return mask;
114}
115
116extern u8 cpu_2_logical_apicid[];
117/* Mapping from cpu number to logical apicid */
118static inline int cpu_to_logical_apicid(int cpu)
119{
Andi Kleen874c4fe2006-09-26 10:52:26 +0200120#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 if (cpu >= NR_CPUS)
122 return BAD_APICID;
123 return (int)cpu_2_logical_apicid[cpu];
Andi Kleen874c4fe2006-09-26 10:52:26 +0200124#else
125 return logical_smp_processor_id();
126#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129static inline physid_mask_t ioapic_phys_id_map(physid_mask_t phys_map)
130{
131 /* For clustered we don't have a good way to do this yet - hack */
132 return physids_promote(0xff);
133}
134
135
136static inline void setup_portio_remap(void)
137{
138}
139
140extern unsigned int boot_cpu_physical_apicid;
141static inline int check_phys_apicid_present(int cpu_physical_apicid)
142{
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700143 boot_cpu_physical_apicid = read_apic_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return (1);
145}
146
147static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
148{
149 int num_bits_set;
150 int cpus_found = 0;
151 int cpu;
Yinghai Luc7e79642008-07-25 02:17:33 -0700152 int apicid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 num_bits_set = cpus_weight(cpumask);
155 /* Return id to all */
156 if (num_bits_set == NR_CPUS)
157#if defined CONFIG_ES7000_CLUSTERED_APIC
158 return 0xFF;
159#else
160 return cpu_to_logical_apicid(0);
161#endif
Yinghai Luc7e79642008-07-25 02:17:33 -0700162 /*
163 * The cpus in the mask must all be on the apic cluster. If are not
164 * on the same apicid cluster return default value of TARGET_CPUS.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 */
166 cpu = first_cpu(cpumask);
167 apicid = cpu_to_logical_apicid(cpu);
168 while (cpus_found < num_bits_set) {
169 if (cpu_isset(cpu, cpumask)) {
170 int new_apicid = cpu_to_logical_apicid(cpu);
Yinghai Luc7e79642008-07-25 02:17:33 -0700171 if (apicid_cluster(apicid) !=
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 apicid_cluster(new_apicid)){
Harvey Harrisond5c003b2008-10-15 22:01:24 -0700173 printk ("%s: Not a valid mask!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174#if defined CONFIG_ES7000_CLUSTERED_APIC
175 return 0xFF;
176#else
177 return cpu_to_logical_apicid(0);
178#endif
179 }
180 apicid = new_apicid;
181 cpus_found++;
182 }
183 cpu++;
184 }
185 return apicid;
186}
187
188static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
189{
190 return cpuid_apic >> index_msb;
191}
192
Yinghai Luc7e79642008-07-25 02:17:33 -0700193#endif /* __ASM_ES7000_APIC_H */