apic_numachip.c 8.5 KB
Newer Older
S
Steffen Persvold 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Numascale NumaConnect-Specific APIC Code
 *
 * Copyright (C) 2011 Numascale AS. All rights reserved.
 *
 * Send feedback to <support@numascale.com>
 *
 */

#include <linux/init.h>

16
#include <asm/numachip/numachip.h>
S
Steffen Persvold 已提交
17 18 19
#include <asm/numachip/numachip_csr.h>
#include <asm/ipi.h>
#include <asm/apic_flat_64.h>
20
#include <asm/pgtable.h>
21
#include <asm/pci_x86.h>
S
Steffen Persvold 已提交
22

23 24
u8 numachip_system __read_mostly;
static const struct apic apic_numachip1;
25
static const struct apic apic_numachip2;
26
static void (*numachip_apic_icr_write)(int apicid, unsigned int val) __read_mostly;
S
Steffen Persvold 已提交
27

28
static unsigned int numachip1_get_apic_id(unsigned long x)
S
Steffen Persvold 已提交
29 30
{
	unsigned long value;
31
	unsigned int id = (x >> 24) & 0xff;
S
Steffen Persvold 已提交
32

33
	if (static_cpu_has(X86_FEATURE_NODEID_MSR)) {
34 35 36
		rdmsrl(MSR_FAM10H_NODE_ID, value);
		id |= (value << 2) & 0xff00;
	}
S
Steffen Persvold 已提交
37 38 39 40

	return id;
}

41
static unsigned long numachip1_set_apic_id(unsigned int id)
S
Steffen Persvold 已提交
42 43 44 45 46 47 48
{
	unsigned long x;

	x = ((id & 0xffU) << 24);
	return x;
}

49 50 51 52 53 54 55 56 57 58 59 60 61
static unsigned int numachip2_get_apic_id(unsigned long x)
{
	u64 mcfg;

	rdmsrl(MSR_FAM10H_MMIO_CONF_BASE, mcfg);
	return ((mcfg >> (28 - 8)) & 0xfff00) | (x >> 24);
}

static unsigned long numachip2_set_apic_id(unsigned int id)
{
	return id << 24;
}

62 63 64 65 66 67
static int numachip_apic_id_valid(int apicid)
{
	/* Trust what bootloader passes in MADT */
	return 1;
}

S
Steffen Persvold 已提交
68 69
static int numachip_apic_id_registered(void)
{
70
	return 1;
S
Steffen Persvold 已提交
71 72 73 74 75 76 77
}

static int numachip_phys_pkg_id(int initial_apic_id, int index_msb)
{
	return initial_apic_id >> index_msb;
}

78
static void numachip1_apic_icr_write(int apicid, unsigned int val)
S
Steffen Persvold 已提交
79
{
80 81
	write_lcsr(CSR_G3_EXT_IRQ_GEN, (apicid << 16) | val);
}
S
Steffen Persvold 已提交
82

83 84 85 86 87
static void numachip2_apic_icr_write(int apicid, unsigned int val)
{
	numachip2_write32_lcsr(NUMACHIP2_APIC_ICR, (apicid << 12) | val);
}

88 89 90 91 92
static int numachip_wakeup_secondary(int phys_apicid, unsigned long start_rip)
{
	numachip_apic_icr_write(phys_apicid, APIC_DM_INIT);
	numachip_apic_icr_write(phys_apicid, APIC_DM_STARTUP |
		(start_rip >> 12));
S
Steffen Persvold 已提交
93 94 95 96 97 98

	return 0;
}

static void numachip_send_IPI_one(int cpu, int vector)
{
99
	int local_apicid, apicid = per_cpu(x86_cpu_to_apicid, cpu);
100
	unsigned int dmode;
S
Steffen Persvold 已提交
101

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
	preempt_disable();
	local_apicid = __this_cpu_read(x86_cpu_to_apicid);

	/* Send via local APIC where non-local part matches */
	if (!((apicid ^ local_apicid) >> NUMACHIP_LAPIC_BITS)) {
		unsigned long flags;

		local_irq_save(flags);
		__default_send_IPI_dest_field(apicid, vector,
			APIC_DEST_PHYSICAL);
		local_irq_restore(flags);
		preempt_enable();
		return;
	}
	preempt_enable();

118 119
	dmode = (vector == NMI_VECTOR) ? APIC_DM_NMI : APIC_DM_FIXED;
	numachip_apic_icr_write(apicid, dmode | vector);
S
Steffen Persvold 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
}

static void numachip_send_IPI_mask(const struct cpumask *mask, int vector)
{
	unsigned int cpu;

	for_each_cpu(cpu, mask)
		numachip_send_IPI_one(cpu, vector);
}

static void numachip_send_IPI_mask_allbutself(const struct cpumask *mask,
						int vector)
{
	unsigned int this_cpu = smp_processor_id();
	unsigned int cpu;

	for_each_cpu(cpu, mask) {
		if (cpu != this_cpu)
			numachip_send_IPI_one(cpu, vector);
	}
}

static void numachip_send_IPI_allbutself(int vector)
{
	unsigned int this_cpu = smp_processor_id();
	unsigned int cpu;

	for_each_online_cpu(cpu) {
		if (cpu != this_cpu)
			numachip_send_IPI_one(cpu, vector);
	}
}

static void numachip_send_IPI_all(int vector)
{
	numachip_send_IPI_mask(cpu_online_mask, vector);
}

static void numachip_send_IPI_self(int vector)
{
160
	apic_write(APIC_SELF_IPI, vector);
S
Steffen Persvold 已提交
161 162
}

163
static int __init numachip1_probe(void)
S
Steffen Persvold 已提交
164
{
165
	return apic == &apic_numachip1;
S
Steffen Persvold 已提交
166 167
}

168 169 170 171 172
static int __init numachip2_probe(void)
{
	return apic == &apic_numachip2;
}

S
Steffen Persvold 已提交
173 174
static void fixup_cpu_id(struct cpuinfo_x86 *c, int node)
{
175 176 177 178 179 180
	u64 val;
	u32 nodes = 1;

	this_cpu_write(cpu_llc_id, node);

	/* Account for nodes per socket in multi-core-module processors */
181
	if (static_cpu_has(X86_FEATURE_NODEID_MSR)) {
182 183
		rdmsrl(MSR_FAM10H_NODE_ID, val);
		nodes = ((val >> 3) & 7) + 1;
184
	}
185 186

	c->phys_proc_id = node / nodes;
S
Steffen Persvold 已提交
187 188 189 190
}

static int __init numachip_system_init(void)
{
191 192 193 194 195 196
	/* Map the LCSR area and set up the apic_icr_write function */
	switch (numachip_system) {
	case 1:
		init_extra_mapping_uc(NUMACHIP_LCSR_BASE, NUMACHIP_LCSR_SIZE);
		numachip_apic_icr_write = numachip1_apic_icr_write;
		break;
197 198 199 200
	case 2:
		init_extra_mapping_uc(NUMACHIP2_LCSR_BASE, NUMACHIP2_LCSR_SIZE);
		numachip_apic_icr_write = numachip2_apic_icr_write;
		break;
201
	default:
S
Steffen Persvold 已提交
202
		return 0;
203
	}
204

S
Steffen Persvold 已提交
205
	x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
206
	x86_init.pci.arch_init = pci_numachip_init;
S
Steffen Persvold 已提交
207 208 209 210 211

	return 0;
}
early_initcall(numachip_system_init);

212
static int numachip1_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
S
Steffen Persvold 已提交
213
{
214 215 216
	if ((strncmp(oem_id, "NUMASC", 6) != 0) ||
	    (strncmp(oem_table_id, "NCONNECT", 8) != 0))
		return 0;
S
Steffen Persvold 已提交
217

218
	numachip_system = 1;
S
Steffen Persvold 已提交
219

220 221
	return 1;
}
S
Steffen Persvold 已提交
222

223 224 225 226 227 228 229 230 231 232 233
static int numachip2_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
{
	if ((strncmp(oem_id, "NUMASC", 6) != 0) ||
	    (strncmp(oem_table_id, "NCONECT2", 8) != 0))
		return 0;

	numachip_system = 2;

	return 1;
}

234 235 236 237 238 239 240 241 242 243 244
/* APIC IPIs are queued */
static void numachip_apic_wait_icr_idle(void)
{
}

/* APIC NMI IPIs are queued */
static u32 numachip_safe_apic_wait_icr_idle(void)
{
	return 0;
}

245
static const struct apic apic_numachip1 __refconst = {
S
Steffen Persvold 已提交
246
	.name				= "NumaConnect system",
247 248
	.probe				= numachip1_probe,
	.acpi_madt_oem_check		= numachip1_acpi_madt_oem_check,
249
	.apic_id_valid			= numachip_apic_id_valid,
S
Steffen Persvold 已提交
250 251 252 253 254
	.apic_id_registered		= numachip_apic_id_registered,

	.irq_delivery_mode		= dest_Fixed,
	.irq_dest_mode			= 0, /* physical */

255
	.target_cpus			= online_target_cpus,
S
Steffen Persvold 已提交
256 257 258 259
	.disable_esr			= 0,
	.dest_logical			= 0,
	.check_apicid_used		= NULL,

260
	.vector_allocation_domain	= default_vector_allocation_domain,
S
Steffen Persvold 已提交
261 262 263 264 265 266 267 268 269
	.init_apic_ldr			= flat_init_apic_ldr,

	.ioapic_phys_id_map		= NULL,
	.setup_apic_routing		= NULL,
	.cpu_present_to_apicid		= default_cpu_present_to_apicid,
	.apicid_to_cpu_present		= NULL,
	.check_phys_apicid_present	= default_check_phys_apicid_present,
	.phys_pkg_id			= numachip_phys_pkg_id,

270 271
	.get_apic_id			= numachip1_get_apic_id,
	.set_apic_id			= numachip1_set_apic_id,
S
Steffen Persvold 已提交
272 273
	.apic_id_mask			= 0xffU << 24,

274
	.cpu_mask_to_apicid_and		= default_cpu_mask_to_apicid_and,
S
Steffen Persvold 已提交
275

276
	.send_IPI			= numachip_send_IPI_one,
S
Steffen Persvold 已提交
277 278 279 280 281 282 283 284 285 286 287
	.send_IPI_mask			= numachip_send_IPI_mask,
	.send_IPI_mask_allbutself	= numachip_send_IPI_mask_allbutself,
	.send_IPI_allbutself		= numachip_send_IPI_allbutself,
	.send_IPI_all			= numachip_send_IPI_all,
	.send_IPI_self			= numachip_send_IPI_self,

	.wakeup_secondary_cpu		= numachip_wakeup_secondary,
	.inquire_remote_apic		= NULL, /* REMRD not supported */

	.read				= native_apic_mem_read,
	.write				= native_apic_mem_write,
288
	.eoi_write			= native_apic_mem_write,
S
Steffen Persvold 已提交
289 290
	.icr_read			= native_apic_icr_read,
	.icr_write			= native_apic_icr_write,
291 292
	.wait_icr_idle			= numachip_apic_wait_icr_idle,
	.safe_wait_icr_idle		= numachip_safe_apic_wait_icr_idle,
S
Steffen Persvold 已提交
293 294
};

295
apic_driver(apic_numachip1);
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327

static const struct apic apic_numachip2 __refconst = {
	.name				= "NumaConnect2 system",
	.probe				= numachip2_probe,
	.acpi_madt_oem_check		= numachip2_acpi_madt_oem_check,
	.apic_id_valid			= numachip_apic_id_valid,
	.apic_id_registered		= numachip_apic_id_registered,

	.irq_delivery_mode		= dest_Fixed,
	.irq_dest_mode			= 0, /* physical */

	.target_cpus			= online_target_cpus,
	.disable_esr			= 0,
	.dest_logical			= 0,
	.check_apicid_used		= NULL,

	.vector_allocation_domain	= default_vector_allocation_domain,
	.init_apic_ldr			= flat_init_apic_ldr,

	.ioapic_phys_id_map		= NULL,
	.setup_apic_routing		= NULL,
	.cpu_present_to_apicid		= default_cpu_present_to_apicid,
	.apicid_to_cpu_present		= NULL,
	.check_phys_apicid_present	= default_check_phys_apicid_present,
	.phys_pkg_id			= numachip_phys_pkg_id,

	.get_apic_id			= numachip2_get_apic_id,
	.set_apic_id			= numachip2_set_apic_id,
	.apic_id_mask			= 0xffU << 24,

	.cpu_mask_to_apicid_and		= default_cpu_mask_to_apicid_and,

328
	.send_IPI			= numachip_send_IPI_one,
329 330 331 332 333 334 335 336 337 338 339 340 341 342
	.send_IPI_mask			= numachip_send_IPI_mask,
	.send_IPI_mask_allbutself	= numachip_send_IPI_mask_allbutself,
	.send_IPI_allbutself		= numachip_send_IPI_allbutself,
	.send_IPI_all			= numachip_send_IPI_all,
	.send_IPI_self			= numachip_send_IPI_self,

	.wakeup_secondary_cpu		= numachip_wakeup_secondary,
	.inquire_remote_apic		= NULL, /* REMRD not supported */

	.read				= native_apic_mem_read,
	.write				= native_apic_mem_write,
	.eoi_write			= native_apic_mem_write,
	.icr_read			= native_apic_icr_read,
	.icr_write			= native_apic_icr_write,
343 344
	.wait_icr_idle			= numachip_apic_wait_icr_idle,
	.safe_wait_icr_idle		= numachip_safe_apic_wait_icr_idle,
345 346 347
};

apic_driver(apic_numachip2);