1 #ifndef __ASM_ES7000_APIC_H
2 #define __ASM_ES7000_APIC_H
6 #define xapic_phys_to_log_apicid(cpu) per_cpu(x86_bios_cpu_apicid, cpu)
7 #define esr_disable (1)
9 static inline int apic_id_registered(void)
14 static inline const cpumask_t *target_cpus_cluster(void)
19 static inline const cpumask_t *target_cpus(void)
21 return &cpumask_of_cpu(smp_processor_id());
24 #define APIC_DFR_VALUE_CLUSTER (APIC_DFR_CLUSTER)
25 #define INT_DELIVERY_MODE_CLUSTER (dest_LowestPrio)
26 #define INT_DEST_MODE_CLUSTER (1) /* logical delivery broadcast to all procs */
27 #define NO_BALANCE_IRQ_CLUSTER (1)
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 */
32 #define NO_BALANCE_IRQ (0)
33 #undef APIC_DEST_LOGICAL
34 #define APIC_DEST_LOGICAL 0x0
36 static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid)
40 static inline unsigned long check_apicid_present(int bit)
42 return physid_isset(bit, phys_cpu_present_map);
45 #define apicid_cluster(apicid) (apicid & 0xF0)
47 static inline unsigned long calculate_ldr(int cpu)
50 id = xapic_phys_to_log_apicid(cpu);
51 return (SET_APIC_LOGICAL_ID(id));
55 * Set up the logical destination ID.
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...
61 static inline void init_apic_ldr_cluster(void)
64 int cpu = smp_processor_id();
66 apic_write(APIC_DFR, APIC_DFR_VALUE_CLUSTER);
67 val = calculate_ldr(cpu);
68 apic_write(APIC_LDR, val);
71 static inline void init_apic_ldr(void)
74 int cpu = smp_processor_id();
76 apic_write(APIC_DFR, APIC_DFR_VALUE);
77 val = calculate_ldr(cpu);
78 apic_write(APIC_LDR, val);
81 extern int apic_version [MAX_APICS];
82 static inline void setup_apic_routing(void)
84 int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id());
85 printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
86 (apic_version[apic] == 0x14) ?
87 "Physical Cluster" : "Logical Cluster",
88 nr_ioapics, cpus_addr(*target_cpus())[0]);
91 static inline int multi_timer_check(int apic, int irq)
96 static inline int apicid_to_node(int logical_apicid)
102 static inline int cpu_present_to_apicid(int mps_cpu)
105 return boot_cpu_physical_apicid;
106 else if (mps_cpu < nr_cpu_ids)
107 return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
112 static inline physid_mask_t apicid_to_cpu_present(int phys_apicid)
116 mask = physid_mask_of_physid(id);
121 extern u8 cpu_2_logical_apicid[];
122 /* Mapping from cpu number to logical apicid */
123 static inline int cpu_to_logical_apicid(int cpu)
126 if (cpu >= nr_cpu_ids)
128 return (int)cpu_2_logical_apicid[cpu];
130 return logical_smp_processor_id();
134 static inline physid_mask_t ioapic_phys_id_map(physid_mask_t phys_map)
136 /* For clustered we don't have a good way to do this yet - hack */
137 return physids_promote(0xff);
141 static inline void setup_portio_remap(void)
145 extern unsigned int boot_cpu_physical_apicid;
146 static inline int check_phys_apicid_present(int cpu_physical_apicid)
148 boot_cpu_physical_apicid = read_apic_id();
152 static inline unsigned int
153 cpu_mask_to_apicid_cluster(const struct cpumask *cpumask)
160 num_bits_set = cpumask_weight(cpumask);
161 /* Return id to all */
162 if (num_bits_set == nr_cpu_ids)
165 * The cpus in the mask must all be on the apic cluster. If are not
166 * on the same apicid cluster return default value of TARGET_CPUS.
168 cpu = cpumask_first(cpumask);
169 apicid = cpu_to_logical_apicid(cpu);
170 while (cpus_found < num_bits_set) {
171 if (cpumask_test_cpu(cpu, cpumask)) {
172 int new_apicid = cpu_to_logical_apicid(cpu);
173 if (apicid_cluster(apicid) !=
174 apicid_cluster(new_apicid)){
175 printk ("%s: Not a valid mask!\n", __func__);
186 static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
193 num_bits_set = cpus_weight(*cpumask);
194 /* Return id to all */
195 if (num_bits_set == nr_cpu_ids)
196 return cpu_to_logical_apicid(0);
198 * The cpus in the mask must all be on the apic cluster. If are not
199 * on the same apicid cluster return default value of TARGET_CPUS.
201 cpu = first_cpu(*cpumask);
202 apicid = cpu_to_logical_apicid(cpu);
203 while (cpus_found < num_bits_set) {
204 if (cpu_isset(cpu, *cpumask)) {
205 int new_apicid = cpu_to_logical_apicid(cpu);
206 if (apicid_cluster(apicid) !=
207 apicid_cluster(new_apicid)){
208 printk ("%s: Not a valid mask!\n", __func__);
209 return cpu_to_logical_apicid(0);
220 static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *inmask,
221 const struct cpumask *andmask)
223 int apicid = cpu_to_logical_apicid(0);
224 cpumask_var_t cpumask;
226 if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC))
229 cpumask_and(cpumask, inmask, andmask);
230 cpumask_and(cpumask, cpumask, cpu_online_mask);
231 apicid = cpu_mask_to_apicid(cpumask);
233 free_cpumask_var(cpumask);
237 static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
239 return cpuid_apic >> index_msb;
242 #endif /* __ASM_ES7000_APIC_H */