blob: 26333685a7fbe50974475026bced9b4ae9c13ca8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_MACH_APIC_H
2#define __ASM_MACH_APIC_H
3
4extern u8 bios_cpu_apicid[];
5
6#define xapic_phys_to_log_apicid(cpu) (bios_cpu_apicid[cpu])
7#define esr_disable (1)
8
9static inline int apic_id_registered(void)
10{
11 return (1);
12}
13
14static inline cpumask_t target_cpus(void)
15{
16#if defined CONFIG_ES7000_CLUSTERED_APIC
17 return CPU_MASK_ALL;
18#else
19 return cpumask_of_cpu(smp_processor_id());
20#endif
21}
22#define TARGET_CPUS (target_cpus())
23
24#if defined CONFIG_ES7000_CLUSTERED_APIC
25#define APIC_DFR_VALUE (APIC_DFR_CLUSTER)
26#define INT_DELIVERY_MODE (dest_LowestPrio)
27#define INT_DEST_MODE (1) /* logical delivery broadcast to all procs */
28#define NO_BALANCE_IRQ (1)
29#undef WAKE_SECONDARY_VIA_INIT
30#define WAKE_SECONDARY_VIA_MIP
31#else
32#define APIC_DFR_VALUE (APIC_DFR_FLAT)
33#define INT_DELIVERY_MODE (dest_Fixed)
34#define INT_DEST_MODE (0) /* phys delivery to target procs */
35#define NO_BALANCE_IRQ (0)
36#undef APIC_DEST_LOGICAL
37#define APIC_DEST_LOGICAL 0x0
38#define WAKE_SECONDARY_VIA_INIT
39#endif
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid)
42{
43 return 0;
44}
45static inline unsigned long check_apicid_present(int bit)
46{
47 return physid_isset(bit, phys_cpu_present_map);
48}
49
50#define apicid_cluster(apicid) (apicid & 0xF0)
51
52static inline unsigned long calculate_ldr(int cpu)
53{
54 unsigned long id;
55 id = xapic_phys_to_log_apicid(cpu);
56 return (SET_APIC_LOGICAL_ID(id));
57}
58
59/*
60 * Set up the logical destination ID.
61 *
62 * Intel recommends to set DFR, LdR and TPR before enabling
63 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
64 * document number 292116). So here it goes...
65 */
66static inline void init_apic_ldr(void)
67{
68 unsigned long val;
69 int cpu = smp_processor_id();
70
71 apic_write_around(APIC_DFR, APIC_DFR_VALUE);
72 val = calculate_ldr(cpu);
73 apic_write_around(APIC_LDR, val);
74}
75
76extern void es7000_sw_apic(void);
77static inline void enable_apic_mode(void)
78{
79 es7000_sw_apic();
80 return;
81}
82
83extern int apic_version [MAX_APICS];
84static inline void clustered_apic_check(void)
85{
86 int apic = bios_cpu_apicid[smp_processor_id()];
87 printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
88 (apic_version[apic] == 0x14) ?
89 "Physical Cluster" : "Logical Cluster", nr_ioapics, cpus_addr(TARGET_CPUS)[0]);
90}
91
92static inline int multi_timer_check(int apic, int irq)
93{
94 return 0;
95}
96
97static inline int apicid_to_node(int logical_apicid)
98{
99 return 0;
100}
101
102
103static inline int cpu_present_to_apicid(int mps_cpu)
104{
105 if (!mps_cpu)
106 return boot_cpu_physical_apicid;
107 else if (mps_cpu < NR_CPUS)
108 return (int) bios_cpu_apicid[mps_cpu];
109 else
110 return BAD_APICID;
111}
112
113static inline physid_mask_t apicid_to_cpu_present(int phys_apicid)
114{
115 static int id = 0;
116 physid_mask_t mask;
117 mask = physid_mask_of_physid(id);
118 ++id;
119 return mask;
120}
121
122extern u8 cpu_2_logical_apicid[];
123/* Mapping from cpu number to logical apicid */
124static inline int cpu_to_logical_apicid(int cpu)
125{
Andi Kleen874c4fe2006-09-26 10:52:26 +0200126#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 if (cpu >= NR_CPUS)
128 return BAD_APICID;
129 return (int)cpu_2_logical_apicid[cpu];
Andi Kleen874c4fe2006-09-26 10:52:26 +0200130#else
131 return logical_smp_processor_id();
132#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
135static inline int mpc_apic_id(struct mpc_config_processor *m, struct mpc_config_translation *unused)
136{
137 printk("Processor #%d %ld:%ld APIC version %d\n",
138 m->mpc_apicid,
139 (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
140 (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
141 m->mpc_apicver);
142 return (m->mpc_apicid);
143}
144
145static inline physid_mask_t ioapic_phys_id_map(physid_mask_t phys_map)
146{
147 /* For clustered we don't have a good way to do this yet - hack */
148 return physids_promote(0xff);
149}
150
151
152static inline void setup_portio_remap(void)
153{
154}
155
156extern unsigned int boot_cpu_physical_apicid;
157static inline int check_phys_apicid_present(int cpu_physical_apicid)
158{
159 boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
160 return (1);
161}
162
163static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
164{
165 int num_bits_set;
166 int cpus_found = 0;
167 int cpu;
168 int apicid;
169
170 num_bits_set = cpus_weight(cpumask);
171 /* Return id to all */
172 if (num_bits_set == NR_CPUS)
173#if defined CONFIG_ES7000_CLUSTERED_APIC
174 return 0xFF;
175#else
176 return cpu_to_logical_apicid(0);
177#endif
178 /*
179 * The cpus in the mask must all be on the apic cluster. If are not
180 * on the same apicid cluster return default value of TARGET_CPUS.
181 */
182 cpu = first_cpu(cpumask);
183 apicid = cpu_to_logical_apicid(cpu);
184 while (cpus_found < num_bits_set) {
185 if (cpu_isset(cpu, cpumask)) {
186 int new_apicid = cpu_to_logical_apicid(cpu);
187 if (apicid_cluster(apicid) !=
188 apicid_cluster(new_apicid)){
189 printk ("%s: Not a valid mask!\n",__FUNCTION__);
190#if defined CONFIG_ES7000_CLUSTERED_APIC
191 return 0xFF;
192#else
193 return cpu_to_logical_apicid(0);
194#endif
195 }
196 apicid = new_apicid;
197 cpus_found++;
198 }
199 cpu++;
200 }
201 return apicid;
202}
203
204static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
205{
206 return cpuid_apic >> index_msb;
207}
208
209#endif /* __ASM_MACH_APIC_H */