patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-i386 / mach-es7000 / mach_apic.h
1 #ifndef __ASM_MACH_APIC_H
2 #define __ASM_MACH_APIC_H
3
4 extern u8 bios_cpu_apicid[];
5
6 #define xapic_phys_to_log_apicid(cpu) (bios_cpu_apicid[cpu])
7 #define esr_disable (1)
8
9 static inline int apic_id_registered(void)
10 {
11                 return (1);
12 }
13
14 static 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(bios_cpu_apicid[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
41 #define APIC_BROADCAST_ID       (0xff)
42 #define NO_IOAPIC_CHECK (1)
43
44 static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid)
45
46         return 0;
47
48 static inline unsigned long check_apicid_present(int bit) 
49 {
50         return physid_isset(bit, phys_cpu_present_map);
51 }
52
53 #define apicid_cluster(apicid) (apicid & 0xF0)
54
55 static inline unsigned long calculate_ldr(int cpu)
56 {
57         unsigned long id;
58         id = xapic_phys_to_log_apicid(cpu);
59         return (SET_APIC_LOGICAL_ID(id));
60 }
61
62 /*
63  * Set up the logical destination ID.
64  *
65  * Intel recommends to set DFR, LdR and TPR before enabling
66  * an APIC.  See e.g. "AP-388 82489DX User's Manual" (Intel
67  * document number 292116).  So here it goes...
68  */
69 static inline void init_apic_ldr(void)
70 {
71         unsigned long val;
72         int cpu = smp_processor_id();
73
74         apic_write_around(APIC_DFR, APIC_DFR_VALUE);
75         val = calculate_ldr(cpu);
76         apic_write_around(APIC_LDR, val);
77 }
78
79 extern void es7000_sw_apic(void);
80 static inline void enable_apic_mode(void)
81 {
82         es7000_sw_apic();
83         return;
84 }
85
86 extern int apic_version [MAX_APICS];
87 static inline void clustered_apic_check(void)
88 {
89         int apic = bios_cpu_apicid[smp_processor_id()];
90         printk("Enabling APIC mode:  %s.  Using %d I/O APICs, target cpus %lx\n",
91                 (apic_version[apic] == 0x14) ? 
92                 "Physical Cluster" : "Logical Cluster", nr_ioapics, cpus_coerce(TARGET_CPUS));
93 }
94
95 static inline int multi_timer_check(int apic, int irq)
96 {
97         return 0;
98 }
99
100 static inline int apicid_to_node(int logical_apicid)
101 {
102         return 0;
103 }
104
105
106 static inline int cpu_present_to_apicid(int mps_cpu)
107 {
108         if (!mps_cpu)
109                 return boot_cpu_physical_apicid;
110         else if (mps_cpu < NR_CPUS)
111                 return (int) bios_cpu_apicid[mps_cpu];
112         else
113                 return BAD_APICID;
114 }
115
116 static inline physid_mask_t apicid_to_cpu_present(int phys_apicid)
117 {
118         static int id = 0;
119         physid_mask_t mask;
120         mask = physid_mask_of_physid(id);
121         ++id;
122         return mask;
123 }
124
125 extern u8 cpu_2_logical_apicid[];
126 /* Mapping from cpu number to logical apicid */
127 static inline int cpu_to_logical_apicid(int cpu)
128 {
129        if (cpu >= NR_CPUS)
130                return BAD_APICID;
131        return (int)cpu_2_logical_apicid[cpu];
132 }
133
134 static inline int mpc_apic_id(struct mpc_config_processor *m, struct mpc_config_translation *unused)
135 {
136         printk("Processor #%d %ld:%ld APIC version %d\n",
137                 m->mpc_apicid,
138                 (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
139                 (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
140                 m->mpc_apicver);
141         return (m->mpc_apicid);
142 }
143
144 static inline physid_mask_t ioapic_phys_id_map(physid_mask_t phys_map)
145 {
146         /* For clustered we don't have a good way to do this yet - hack */
147         return physids_promote(0xff);
148 }
149
150
151 static inline void setup_portio_remap(void)
152 {
153 }
154
155 extern unsigned int boot_cpu_physical_apicid;
156 static inline int check_phys_apicid_present(int cpu_physical_apicid)
157 {
158         boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
159         return (1);
160 }
161
162 static inline unsigned int cpu_mask_to_apicid(cpumask_const_t cpumask)
163 {
164         int num_bits_set;
165         int cpus_found = 0;
166         int cpu;
167         int apicid;     
168
169         num_bits_set = cpus_weight_const(cpumask);
170         /* Return id to all */
171         if (num_bits_set == NR_CPUS)
172 #if defined CONFIG_ES7000_CLUSTERED_APIC
173                 return 0xFF;
174 #else
175                 return cpu_to_logical_apicid(0);
176 #endif
177         /* 
178          * The cpus in the mask must all be on the apic cluster.  If are not 
179          * on the same apicid cluster return default value of TARGET_CPUS. 
180          */
181         cpu = first_cpu_const(cpumask);
182         apicid = cpu_to_logical_apicid(cpu);
183         while (cpus_found < num_bits_set) {
184                 if (cpu_isset_const(cpu, cpumask)) {
185                         int new_apicid = cpu_to_logical_apicid(cpu);
186                         if (apicid_cluster(apicid) != 
187                                         apicid_cluster(new_apicid)){
188                                 printk ("%s: Not a valid mask!\n",__FUNCTION__);
189 #if defined CONFIG_ES7000_CLUSTERED_APIC
190                                 return 0xFF;
191 #else
192                                 return cpu_to_logical_apicid(0);
193 #endif
194                         }
195                         apicid = new_apicid;
196                         cpus_found++;
197                 }
198                 cpu++;
199         }
200         return apicid;
201 }
202
203 static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
204 {
205         return cpuid_apic >> index_msb;
206 }
207
208 #endif /* __ASM_MACH_APIC_H */