2011-12-05 23:07:26 +07:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
2012-12-08 04:24:32 +07:00
|
|
|
#include <asm/numachip/numachip.h>
|
2011-12-05 23:07:26 +07:00
|
|
|
#include <asm/numachip/numachip_csr.h>
|
|
|
|
#include <asm/ipi.h>
|
|
|
|
#include <asm/apic_flat_64.h>
|
2012-11-17 04:53:09 +07:00
|
|
|
#include <asm/pgtable.h>
|
2015-09-21 00:01:59 +07:00
|
|
|
#include <asm/pci_x86.h>
|
2011-12-05 23:07:26 +07:00
|
|
|
|
2015-09-21 00:01:59 +07:00
|
|
|
u8 numachip_system __read_mostly;
|
|
|
|
static const struct apic apic_numachip1;
|
2015-09-21 00:02:00 +07:00
|
|
|
static const struct apic apic_numachip2;
|
2015-09-21 00:01:59 +07:00
|
|
|
static void (*numachip_apic_icr_write)(int apicid, unsigned int val) __read_mostly;
|
2011-12-05 23:07:26 +07:00
|
|
|
|
2015-09-21 00:01:59 +07:00
|
|
|
static unsigned int numachip1_get_apic_id(unsigned long x)
|
2011-12-05 23:07:26 +07:00
|
|
|
{
|
|
|
|
unsigned long value;
|
2015-03-12 22:55:13 +07:00
|
|
|
unsigned int id = (x >> 24) & 0xff;
|
2011-12-05 23:07:26 +07:00
|
|
|
|
2016-01-27 04:12:05 +07:00
|
|
|
if (static_cpu_has(X86_FEATURE_NODEID_MSR)) {
|
2015-03-12 22:55:13 +07:00
|
|
|
rdmsrl(MSR_FAM10H_NODE_ID, value);
|
|
|
|
id |= (value << 2) & 0xff00;
|
|
|
|
}
|
2011-12-05 23:07:26 +07:00
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2017-09-14 04:29:17 +07:00
|
|
|
static u32 numachip1_set_apic_id(unsigned int id)
|
2011-12-05 23:07:26 +07:00
|
|
|
{
|
2016-09-11 12:58:21 +07:00
|
|
|
return (id & 0xff) << 24;
|
2011-12-05 23:07:26 +07:00
|
|
|
}
|
|
|
|
|
2015-09-21 00:02:00 +07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-09-14 04:29:17 +07:00
|
|
|
static u32 numachip2_set_apic_id(unsigned int id)
|
2015-09-21 00:02:00 +07:00
|
|
|
{
|
|
|
|
return id << 24;
|
|
|
|
}
|
|
|
|
|
2012-03-14 14:17:34 +07:00
|
|
|
static int numachip_apic_id_valid(int apicid)
|
|
|
|
{
|
|
|
|
/* Trust what bootloader passes in MADT */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-12-05 23:07:26 +07:00
|
|
|
static int numachip_apic_id_registered(void)
|
|
|
|
{
|
2015-09-21 00:01:59 +07:00
|
|
|
return 1;
|
2011-12-05 23:07:26 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int numachip_phys_pkg_id(int initial_apic_id, int index_msb)
|
|
|
|
{
|
|
|
|
return initial_apic_id >> index_msb;
|
|
|
|
}
|
|
|
|
|
2015-09-21 00:01:59 +07:00
|
|
|
static void numachip1_apic_icr_write(int apicid, unsigned int val)
|
2011-12-05 23:07:26 +07:00
|
|
|
{
|
2015-09-21 00:01:59 +07:00
|
|
|
write_lcsr(CSR_G3_EXT_IRQ_GEN, (apicid << 16) | val);
|
|
|
|
}
|
2011-12-05 23:07:26 +07:00
|
|
|
|
2015-09-21 00:02:00 +07:00
|
|
|
static void numachip2_apic_icr_write(int apicid, unsigned int val)
|
|
|
|
{
|
|
|
|
numachip2_write32_lcsr(NUMACHIP2_APIC_ICR, (apicid << 12) | val);
|
|
|
|
}
|
|
|
|
|
2015-09-21 00:01:59 +07:00
|
|
|
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));
|
2011-12-05 23:07:26 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void numachip_send_IPI_one(int cpu, int vector)
|
|
|
|
{
|
2015-09-21 00:02:01 +07:00
|
|
|
int local_apicid, apicid = per_cpu(x86_cpu_to_apicid, cpu);
|
2015-09-21 00:01:59 +07:00
|
|
|
unsigned int dmode;
|
2011-12-05 23:07:26 +07:00
|
|
|
|
2015-09-21 00:02:01 +07:00
|
|
|
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();
|
|
|
|
|
2015-09-21 00:01:59 +07:00
|
|
|
dmode = (vector == NMI_VECTOR) ? APIC_DM_NMI : APIC_DM_FIXED;
|
|
|
|
numachip_apic_icr_write(apicid, dmode | vector);
|
2011-12-05 23:07:26 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2014-11-04 15:29:42 +07:00
|
|
|
apic_write(APIC_SELF_IPI, vector);
|
2011-12-05 23:07:26 +07:00
|
|
|
}
|
|
|
|
|
2015-09-21 00:01:59 +07:00
|
|
|
static int __init numachip1_probe(void)
|
2011-12-05 23:07:26 +07:00
|
|
|
{
|
2015-09-21 00:01:59 +07:00
|
|
|
return apic == &apic_numachip1;
|
2011-12-05 23:07:26 +07:00
|
|
|
}
|
|
|
|
|
2015-09-21 00:02:00 +07:00
|
|
|
static int __init numachip2_probe(void)
|
|
|
|
{
|
|
|
|
return apic == &apic_numachip2;
|
|
|
|
}
|
|
|
|
|
2011-12-05 23:07:26 +07:00
|
|
|
static void fixup_cpu_id(struct cpuinfo_x86 *c, int node)
|
|
|
|
{
|
2015-03-12 22:55:13 +07:00
|
|
|
u64 val;
|
|
|
|
u32 nodes = 1;
|
|
|
|
|
|
|
|
this_cpu_write(cpu_llc_id, node);
|
|
|
|
|
|
|
|
/* Account for nodes per socket in multi-core-module processors */
|
2016-01-27 04:12:05 +07:00
|
|
|
if (static_cpu_has(X86_FEATURE_NODEID_MSR)) {
|
2015-03-12 22:55:13 +07:00
|
|
|
rdmsrl(MSR_FAM10H_NODE_ID, val);
|
|
|
|
nodes = ((val >> 3) & 7) + 1;
|
2012-04-02 23:06:48 +07:00
|
|
|
}
|
2015-03-12 22:55:13 +07:00
|
|
|
|
|
|
|
c->phys_proc_id = node / nodes;
|
2011-12-05 23:07:26 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init numachip_system_init(void)
|
|
|
|
{
|
2015-09-21 00:01:59 +07:00
|
|
|
/* 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;
|
2015-09-21 00:02:00 +07:00
|
|
|
case 2:
|
|
|
|
init_extra_mapping_uc(NUMACHIP2_LCSR_BASE, NUMACHIP2_LCSR_SIZE);
|
|
|
|
numachip_apic_icr_write = numachip2_apic_icr_write;
|
|
|
|
break;
|
2015-09-21 00:01:59 +07:00
|
|
|
default:
|
2011-12-05 23:07:26 +07:00
|
|
|
return 0;
|
2015-09-21 00:01:59 +07:00
|
|
|
}
|
2014-11-04 15:29:43 +07:00
|
|
|
|
2011-12-05 23:07:26 +07:00
|
|
|
x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
|
2015-12-31 01:06:47 +07:00
|
|
|
x86_init.pci.arch_init = pci_numachip_init;
|
2011-12-05 23:07:26 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_initcall(numachip_system_init);
|
|
|
|
|
2015-09-21 00:01:59 +07:00
|
|
|
static int numachip1_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
|
2011-12-05 23:07:26 +07:00
|
|
|
{
|
2015-09-21 00:01:59 +07:00
|
|
|
if ((strncmp(oem_id, "NUMASC", 6) != 0) ||
|
|
|
|
(strncmp(oem_table_id, "NCONNECT", 8) != 0))
|
|
|
|
return 0;
|
2011-12-05 23:07:26 +07:00
|
|
|
|
2015-09-21 00:01:59 +07:00
|
|
|
numachip_system = 1;
|
2011-12-05 23:07:26 +07:00
|
|
|
|
2015-09-21 00:01:59 +07:00
|
|
|
return 1;
|
|
|
|
}
|
2011-12-05 23:07:26 +07:00
|
|
|
|
2015-09-21 00:02:00 +07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-09-21 00:02:01 +07:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2015-09-21 00:01:59 +07:00
|
|
|
static const struct apic apic_numachip1 __refconst = {
|
2011-12-05 23:07:26 +07:00
|
|
|
.name = "NumaConnect system",
|
2015-09-21 00:01:59 +07:00
|
|
|
.probe = numachip1_probe,
|
|
|
|
.acpi_madt_oem_check = numachip1_acpi_madt_oem_check,
|
2012-03-14 14:17:34 +07:00
|
|
|
.apic_id_valid = numachip_apic_id_valid,
|
2011-12-05 23:07:26 +07:00
|
|
|
.apic_id_registered = numachip_apic_id_registered,
|
|
|
|
|
|
|
|
.irq_delivery_mode = dest_Fixed,
|
|
|
|
.irq_dest_mode = 0, /* physical */
|
|
|
|
|
|
|
|
.disable_esr = 0,
|
|
|
|
.dest_logical = 0,
|
|
|
|
.check_apicid_used = NULL,
|
|
|
|
|
|
|
|
.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,
|
|
|
|
|
2015-09-21 00:01:59 +07:00
|
|
|
.get_apic_id = numachip1_get_apic_id,
|
|
|
|
.set_apic_id = numachip1_set_apic_id,
|
2011-12-05 23:07:26 +07:00
|
|
|
|
2017-09-14 04:29:37 +07:00
|
|
|
.calc_dest_apicid = apic_default_calc_apicid,
|
2011-12-05 23:07:26 +07:00
|
|
|
|
2015-11-05 05:57:06 +07:00
|
|
|
.send_IPI = numachip_send_IPI_one,
|
2011-12-05 23:07:26 +07:00
|
|
|
.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,
|
2012-05-16 23:03:52 +07:00
|
|
|
.eoi_write = native_apic_mem_write,
|
2011-12-05 23:07:26 +07:00
|
|
|
.icr_read = native_apic_icr_read,
|
|
|
|
.icr_write = native_apic_icr_write,
|
2015-09-21 00:02:01 +07:00
|
|
|
.wait_icr_idle = numachip_apic_wait_icr_idle,
|
|
|
|
.safe_wait_icr_idle = numachip_safe_apic_wait_icr_idle,
|
2011-12-05 23:07:26 +07:00
|
|
|
};
|
|
|
|
|
2015-09-21 00:01:59 +07:00
|
|
|
apic_driver(apic_numachip1);
|
2015-09-21 00:02:00 +07:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
.disable_esr = 0,
|
|
|
|
.dest_logical = 0,
|
|
|
|
.check_apicid_used = NULL,
|
|
|
|
|
|
|
|
.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,
|
|
|
|
|
2017-09-14 04:29:37 +07:00
|
|
|
.calc_dest_apicid = apic_default_calc_apicid,
|
2015-09-21 00:02:00 +07:00
|
|
|
|
2015-11-05 05:57:06 +07:00
|
|
|
.send_IPI = numachip_send_IPI_one,
|
2015-09-21 00:02:00 +07:00
|
|
|
.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,
|
2015-09-21 00:02:01 +07:00
|
|
|
.wait_icr_idle = numachip_apic_wait_icr_idle,
|
|
|
|
.safe_wait_icr_idle = numachip_safe_apic_wait_icr_idle,
|
2015-09-21 00:02:00 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
apic_driver(apic_numachip2);
|