apic.h 5.4 KB
Newer Older
Y
Yinghai Lu 已提交
1 2
#ifndef __ASM_ES7000_APIC_H
#define __ASM_ES7000_APIC_H
L
Linus Torvalds 已提交
3

4 5
#include <linux/gfp.h>

6
#define xapic_phys_to_log_apicid(cpu) per_cpu(x86_bios_cpu_apicid, cpu)
L
Linus Torvalds 已提交
7

8
static inline int es7000_apic_id_registered(void)
L
Linus Torvalds 已提交
9
{
10
	        return 1;
L
Linus Torvalds 已提交
11 12
}

13
static inline const cpumask_t *target_cpus_cluster(void)
Y
Yinghai Lu 已提交
14
{
15
	return &CPU_MASK_ALL;
16 17
}

18
static inline const cpumask_t *es7000_target_cpus(void)
19
{
20
	return &cpumask_of_cpu(smp_processor_id());
L
Linus Torvalds 已提交
21 22
}

23 24 25 26
#define APIC_DFR_VALUE_CLUSTER		(APIC_DFR_CLUSTER)
#define INT_DELIVERY_MODE_CLUSTER	(dest_LowestPrio)
#define INT_DEST_MODE_CLUSTER		(1) /* logical delivery broadcast to all procs */

L
Linus Torvalds 已提交
27 28
#define APIC_DFR_VALUE		(APIC_DFR_FLAT)

29 30
static inline unsigned long
es7000_check_apicid_used(physid_mask_t bitmap, int apicid)
Y
Yinghai Lu 已提交
31
{
L
Linus Torvalds 已提交
32
	return 0;
Y
Yinghai Lu 已提交
33
}
34
static inline unsigned long es7000_check_apicid_present(int bit)
L
Linus Torvalds 已提交
35 36 37 38
{
	return physid_isset(bit, phys_cpu_present_map);
}

39 40
extern void es7000_enable_apic_mode(void);

L
Linus Torvalds 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#define apicid_cluster(apicid) (apicid & 0xF0)

static inline unsigned long calculate_ldr(int cpu)
{
	unsigned long id;
	id = xapic_phys_to_log_apicid(cpu);
	return (SET_APIC_LOGICAL_ID(id));
}

/*
 * Set up the logical destination ID.
 *
 * Intel recommends to set DFR, LdR and TPR before enabling
 * an APIC.  See e.g. "AP-388 82489DX User's Manual" (Intel
 * document number 292116).  So here it goes...
 */
57
static inline void es7000_init_apic_ldr_cluster(void)
58 59 60 61 62 63 64 65 66
{
	unsigned long val;
	int cpu = smp_processor_id();

	apic_write(APIC_DFR, APIC_DFR_VALUE_CLUSTER);
	val = calculate_ldr(cpu);
	apic_write(APIC_LDR, val);
}

67
static inline void es7000_init_apic_ldr(void)
L
Linus Torvalds 已提交
68 69 70 71
{
	unsigned long val;
	int cpu = smp_processor_id();

72
	apic_write(APIC_DFR, APIC_DFR_VALUE);
L
Linus Torvalds 已提交
73
	val = calculate_ldr(cpu);
74
	apic_write(APIC_LDR, val);
L
Linus Torvalds 已提交
75 76 77
}

extern int apic_version [MAX_APICS];
78
static inline void es7000_setup_apic_routing(void)
L
Linus Torvalds 已提交
79
{
80
	int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id());
81
	printk("Enabling APIC mode:  %s. Using %d I/O APICs, target cpus %lx\n",
Y
Yinghai Lu 已提交
82
		(apic_version[apic] == 0x14) ?
83
			"Physical Cluster" : "Logical Cluster",
84
			nr_ioapics, cpus_addr(*es7000_target_cpus())[0]);
L
Linus Torvalds 已提交
85 86
}

87
static inline int es7000_apicid_to_node(int logical_apicid)
L
Linus Torvalds 已提交
88 89 90 91 92
{
	return 0;
}


93
static inline int es7000_cpu_present_to_apicid(int mps_cpu)
L
Linus Torvalds 已提交
94 95 96
{
	if (!mps_cpu)
		return boot_cpu_physical_apicid;
97
	else if (mps_cpu < nr_cpu_ids)
98
		return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
L
Linus Torvalds 已提交
99 100 101 102
	else
		return BAD_APICID;
}

103
static inline physid_mask_t es7000_apicid_to_cpu_present(int phys_apicid)
L
Linus Torvalds 已提交
104 105 106 107 108 109 110 111 112 113
{
	static int id = 0;
	physid_mask_t mask;
	mask = physid_mask_of_physid(id);
	++id;
	return mask;
}

extern u8 cpu_2_logical_apicid[];
/* Mapping from cpu number to logical apicid */
114
static inline int es7000_cpu_to_logical_apicid(int cpu)
L
Linus Torvalds 已提交
115
{
116
#ifdef CONFIG_SMP
117 118 119
	if (cpu >= nr_cpu_ids)
		return BAD_APICID;
	return (int)cpu_2_logical_apicid[cpu];
120 121 122
#else
	return logical_smp_processor_id();
#endif
L
Linus Torvalds 已提交
123 124
}

125
static inline physid_mask_t es7000_ioapic_phys_id_map(physid_mask_t phys_map)
L
Linus Torvalds 已提交
126 127 128 129 130 131
{
	/* For clustered we don't have a good way to do this yet - hack */
	return physids_promote(0xff);
}

extern unsigned int boot_cpu_physical_apicid;
132 133

static inline int es7000_check_phys_apicid_present(int cpu_physical_apicid)
L
Linus Torvalds 已提交
134
{
135
	boot_cpu_physical_apicid = read_apic_id();
L
Linus Torvalds 已提交
136 137 138
	return (1);
}

139 140
static inline unsigned int
cpu_mask_to_apicid_cluster(const struct cpumask *cpumask)
L
Linus Torvalds 已提交
141 142 143 144
{
	int num_bits_set;
	int cpus_found = 0;
	int cpu;
Y
Yinghai Lu 已提交
145
	int apicid;
L
Linus Torvalds 已提交
146

147
	num_bits_set = cpumask_weight(cpumask);
L
Linus Torvalds 已提交
148
	/* Return id to all */
149
	if (num_bits_set == nr_cpu_ids)
L
Linus Torvalds 已提交
150
		return 0xFF;
Y
Yinghai Lu 已提交
151 152
	/*
	 * The cpus in the mask must all be on the apic cluster.  If are not
153
	 * on the same apicid cluster return default value of target_cpus():
L
Linus Torvalds 已提交
154
	 */
155
	cpu = cpumask_first(cpumask);
156
	apicid = es7000_cpu_to_logical_apicid(cpu);
L
Linus Torvalds 已提交
157
	while (cpus_found < num_bits_set) {
158
		if (cpumask_test_cpu(cpu, cpumask)) {
159
			int new_apicid = es7000_cpu_to_logical_apicid(cpu);
Y
Yinghai Lu 已提交
160
			if (apicid_cluster(apicid) !=
L
Linus Torvalds 已提交
161
					apicid_cluster(new_apicid)){
162
				printk ("%s: Not a valid mask!\n", __func__);
L
Linus Torvalds 已提交
163
				return 0xFF;
164 165 166 167 168 169 170 171 172
			}
			apicid = new_apicid;
			cpus_found++;
		}
		cpu++;
	}
	return apicid;
}

173
static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
174 175 176 177 178 179
{
	int num_bits_set;
	int cpus_found = 0;
	int cpu;
	int apicid;

180
	num_bits_set = cpus_weight(*cpumask);
181
	/* Return id to all */
182
	if (num_bits_set == nr_cpu_ids)
183
		return es7000_cpu_to_logical_apicid(0);
184 185
	/*
	 * The cpus in the mask must all be on the apic cluster.  If are not
186
	 * on the same apicid cluster return default value of target_cpus():
187
	 */
188
	cpu = first_cpu(*cpumask);
189
	apicid = es7000_cpu_to_logical_apicid(cpu);
190
	while (cpus_found < num_bits_set) {
191
		if (cpu_isset(cpu, *cpumask)) {
192
			int new_apicid = es7000_cpu_to_logical_apicid(cpu);
193 194 195
			if (apicid_cluster(apicid) !=
					apicid_cluster(new_apicid)){
				printk ("%s: Not a valid mask!\n", __func__);
196
				return es7000_cpu_to_logical_apicid(0);
L
Linus Torvalds 已提交
197 198 199 200 201 202 203 204 205
			}
			apicid = new_apicid;
			cpus_found++;
		}
		cpu++;
	}
	return apicid;
}

206 207

static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *inmask,
208
						  const struct cpumask *andmask)
M
Mike Travis 已提交
209
{
210
	int apicid = es7000_cpu_to_logical_apicid(0);
211 212 213 214 215 216 217
	cpumask_var_t cpumask;

	if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC))
		return apicid;

	cpumask_and(cpumask, inmask, andmask);
	cpumask_and(cpumask, cpumask, cpu_online_mask);
218
	apicid = cpu_mask_to_apicid(cpumask);
M
Mike Travis 已提交
219

220
	free_cpumask_var(cpumask);
M
Mike Travis 已提交
221 222 223
	return apicid;
}

L
Linus Torvalds 已提交
224 225 226 227 228
static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
{
	return cpuid_apic >> index_msb;
}

Y
Yinghai Lu 已提交
229
#endif /* __ASM_ES7000_APIC_H */