ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-i386 / mach-bigsmp / mach_apic.h
1 #ifndef __ASM_MACH_APIC_H
2 #define __ASM_MACH_APIC_H
3 #include <asm/smp.h>
4
5 #define SEQUENTIAL_APICID
6 #ifdef SEQUENTIAL_APICID
7 #define xapic_phys_to_log_apicid(phys_apic) ( (1ul << ((phys_apic) & 0x3)) |\
8                 ((phys_apic<<2) & (~0xf)) )
9 #elif CLUSTERED_APICID
10 #define xapic_phys_to_log_apicid(phys_apic) ( (1ul << ((phys_apic) & 0x3)) |\
11                 ((phys_apic) & (~0xf)) )
12 #endif
13
14 #define NO_BALANCE_IRQ (1)
15 #define esr_disable (1)
16
17 #define NO_IOAPIC_CHECK (0)
18
19 static inline int apic_id_registered(void)
20 {
21         return (1);
22 }
23
24 #define APIC_DFR_VALUE  (APIC_DFR_CLUSTER)
25 static inline cpumask_t target_cpus(void)
26
27         return cpu_online_map;
28 }
29 #define TARGET_CPUS     (target_cpus())
30
31 #define INT_DELIVERY_MODE dest_LowestPrio
32 #define INT_DEST_MODE 1     /* logical delivery broadcast to all procs */
33
34 #define APIC_BROADCAST_ID     (0xff)
35 static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid)
36 {
37         return 0;
38 }
39
40 /* we don't use the phys_cpu_present_map to indicate apicid presence */
41 static inline unsigned long check_apicid_present(int bit) 
42 {
43         return 1;
44 }
45
46 #define apicid_cluster(apicid) (apicid & 0xF0)
47
48 static inline unsigned long calculate_ldr(unsigned long old)
49 {
50         unsigned long id;
51         id = xapic_phys_to_log_apicid(hard_smp_processor_id());
52         return ((old & ~APIC_LDR_MASK) | SET_APIC_LOGICAL_ID(id));
53 }
54
55 /*
56  * Set up the logical destination ID.
57  *
58  * Intel recommends to set DFR, LDR and TPR before enabling
59  * an APIC.  See e.g. "AP-388 82489DX User's Manual" (Intel
60  * document number 292116).  So here it goes...
61  */
62 static inline void init_apic_ldr(void)
63 {
64         unsigned long val;
65
66         apic_write_around(APIC_DFR, APIC_DFR_VALUE);
67         val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
68         val = calculate_ldr(val);
69         apic_write_around(APIC_LDR, val);
70 }
71
72 static inline void clustered_apic_check(void)
73 {
74         printk("Enabling APIC mode:  %s.  Using %d I/O APICs\n",
75                 "Cluster", nr_ioapics);
76 }
77
78 static inline int multi_timer_check(int apic, int irq)
79 {
80         return 0;
81 }
82
83 static inline int apicid_to_node(int logical_apicid)
84 {
85         return 0;
86 }
87
88 extern u8 bios_cpu_apicid[];
89
90 static inline int cpu_present_to_apicid(int mps_cpu)
91 {
92         if (mps_cpu < NR_CPUS)
93                 return (int)bios_cpu_apicid[mps_cpu];
94         else
95                 return BAD_APICID;
96 }
97
98 static inline physid_mask_t apicid_to_cpu_present(int phys_apicid)
99 {
100         return physid_mask_of_physid(phys_apicid);
101 }
102
103 extern u8 cpu_2_logical_apicid[];
104 /* Mapping from cpu number to logical apicid */
105 static inline int cpu_to_logical_apicid(int cpu)
106 {
107        if (cpu >= NR_CPUS)
108                return BAD_APICID;
109        return (int)cpu_2_logical_apicid[cpu];
110  }
111
112 static inline int mpc_apic_id(struct mpc_config_processor *m,
113                         struct mpc_config_translation *translation_record)
114 {
115         printk("Processor #%d %ld:%ld APIC version %d\n",
116                 m->mpc_apicid,
117                 (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
118                 (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
119                 m->mpc_apicver);
120         return m->mpc_apicid;
121 }
122
123 static inline physid_mask_t ioapic_phys_id_map(physid_mask_t phys_map)
124 {
125         /* For clustered we don't have a good way to do this yet - hack */
126         return physids_promote(0xFUL);
127 }
128
129 #define WAKE_SECONDARY_VIA_INIT
130
131 static inline void setup_portio_remap(void)
132 {
133 }
134
135 static inline void enable_apic_mode(void)
136 {
137 }
138
139 static inline int check_phys_apicid_present(int boot_cpu_physical_apicid)
140 {
141         return (1);
142 }
143
144 static inline unsigned int cpu_mask_to_apicid(cpumask_const_t cpumask)
145 {
146         int num_bits_set;
147         int cpus_found = 0;
148         int cpu;
149         int apicid;     
150
151         num_bits_set = cpus_weight_const(cpumask);
152         /* Return id to all */
153         if (num_bits_set == NR_CPUS)
154                 return (int) 0xFF;
155         /* 
156          * The cpus in the mask must all be on the apic cluster.  If are not 
157          * on the same apicid cluster return default value of TARGET_CPUS. 
158          */
159         cpu = first_cpu_const(cpumask);
160         apicid = cpu_to_logical_apicid(cpu);
161         while (cpus_found < num_bits_set) {
162                 if (cpu_isset_const(cpu, cpumask)) {
163                         int new_apicid = cpu_to_logical_apicid(cpu);
164                         if (apicid_cluster(apicid) != 
165                                         apicid_cluster(new_apicid)){
166                                 printk ("%s: Not a valid mask!\n",__FUNCTION__);
167                                 return 0xFF;
168                         }
169                         apicid = apicid | new_apicid;
170                         cpus_found++;
171                 }
172                 cpu++;
173         }
174         return apicid;
175 }
176
177 static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
178 {
179         return cpuid_apic >> index_msb;
180 }
181
182 #endif /* __ASM_MACH_APIC_H */