31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/reboot.h>
40 #include <linux/string.h>
41 #include <linux/types.h>
42 #include <linux/errno.h>
52 #include <asm/fixmap.h>
54 #include <asm/setup.h>
63 #define ES7000_CLASSIC 1
64 #define ES7000_ZORRO 2
67 #define MIP_PSAI_REG 4
70 #define MIP_SPIN 0xf0000
71 #define MIP_VALID 0x0100000000000000ULL
72 #define MIP_SW_APIC 0x1020b
74 #define MIP_PORT(val) ((val >> 32) & 0xffff)
76 #define MIP_RD_LO(val) (val & 0xffffffff)
104 struct es7000_oem_table {
110 static unsigned long oem_addrX;
111 static unsigned long oem_size;
119 static volatile unsigned long *
psai;
121 static struct mip_reg *host_reg;
123 static unsigned long mip_addr;
124 static unsigned long host_addr;
133 static int __cpuinit wakeup_secondary_cpu_via_mip(
int cpu,
unsigned long eip)
135 unsigned long vect = 0, psaival = 0;
140 vect = ((
unsigned long)
__pa(eip)/0x1000) << 16;
141 psaival = (0x1000000 | vect |
cpu);
143 while (*
psai & 0x1000000)
151 static int es7000_apic_is_cluster(
void)
161 static void setup_unisys(
void)
179 static int parse_unisys_oem(
char *oemptr)
188 struct mip_reg *
host, *mip;
194 for (i = 0; i <= 6; i++) {
203 host = (
struct mip_reg *)val;
204 host_reg =
__va(host);
208 mip = (
struct mip_reg *)val;
211 (
unsigned long)host_reg);
213 (
unsigned long)mip_reg);
217 psaip = (
struct psai *)tp;
241 static int __init find_unisys_acpi_oem_table(
unsigned long *oem_addr)
244 struct es7000_oem_table *
table;
260 table = (
void *)header;
262 oem_addrX = table->OEMTableAddr;
263 oem_size = table->OEMTableSize;
272 static void __init unmap_unisys_acpi_oem_table(
unsigned long oem_addr)
280 static int es7000_check_dsdt(
void)
290 static int es7000_acpi_ret;
295 unsigned long oem_addr = 0;
300 check_dsdt = es7000_check_dsdt();
302 if (!find_unisys_acpi_oem_table(&oem_addr)) {
304 ret = parse_unisys_oem((
char *)oem_addr);
312 unmap_unisys_acpi_oem_table(oem_addr);
315 es7000_acpi_ret =
ret;
317 return ret && !es7000_apic_is_cluster();
320 static int es7000_acpi_madt_oem_check_cluster(
char *oem_id,
char *oem_table_id)
322 int ret = es7000_acpi_ret;
324 return ret && es7000_apic_is_cluster();
328 static int es7000_acpi_madt_oem_check(
char *oem_id,
char *oem_table_id)
333 static int es7000_acpi_madt_oem_check_cluster(
char *oem_id,
char *oem_table_id)
339 static void es7000_spin(
int n)
347 static int es7000_mip_write(
struct mip_reg *mip_reg)
355 WARN(1,
"Timeout waiting for Host Valid Flag\n");
361 memcpy(host_reg, mip_reg,
sizeof(
struct mip_reg));
368 WARN(1,
"Timeout waiting for MIP Valid Flag\n");
374 status = (mip_reg->
off_0x00 & 0xffff0000000000ULL) >> 48;
380 static void es7000_enable_apic_mode(
void)
382 struct mip_reg es7000_mip_reg;
388 pr_info(
"Enabling APIC mode.\n");
389 memset(&es7000_mip_reg, 0,
sizeof(
struct mip_reg));
393 while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0)
394 WARN(1,
"Command failed, status = %x\n", mip_status);
397 static void es7000_wait_for_init_deassert(
atomic_t *deassert)
403 static unsigned int es7000_get_apic_id(
unsigned long x)
405 return (x >> 24) & 0xFF;
413 static void es7000_send_IPI_allbutself(
int vector)
418 static void es7000_send_IPI_all(
int vector)
420 es7000_send_IPI_mask(cpu_online_mask, vector);
423 static int es7000_apic_id_registered(
void)
428 static const struct cpumask *target_cpus_cluster(
void)
433 static const struct cpumask *es7000_target_cpus(
void)
443 static unsigned long es7000_check_apicid_present(
int bit)
448 static int es7000_early_logical_apicid(
int cpu)
454 static unsigned long calculate_ldr(
int cpu)
456 unsigned long id =
per_cpu(x86_bios_cpu_apicid, cpu);
468 static void es7000_init_apic_ldr_cluster(
void)
474 val = calculate_ldr(cpu);
478 static void es7000_init_apic_ldr(
void)
484 val = calculate_ldr(cpu);
488 static void es7000_setup_apic_routing(
void)
492 pr_info(
"Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
494 "Physical Cluster" :
"Logical Cluster",
498 static int es7000_cpu_present_to_apicid(
int mps_cpu)
502 else if (mps_cpu < nr_cpu_ids)
503 return per_cpu(x86_bios_cpu_apicid, mps_cpu);
510 static void es7000_apicid_to_cpu_present(
int phys_apicid,
physid_mask_t *retmap)
512 physid_set_mask_of_physid(cpu_id, retmap);
519 physids_promote(0xFFL, retmap);
522 static int es7000_check_phys_apicid_present(
int cpu_physical_apicid)
531 unsigned int round = 0;
538 int new_apicid =
early_per_cpu(x86_cpu_to_logical_apicid, cpu);
541 WARN(1,
"Not a valid mask!");
555 es7000_cpu_mask_to_apicid_and(
const struct cpumask *inmask,
556 const struct cpumask *andmask,
565 cpumask_and(cpumask, inmask, andmask);
566 es7000_cpu_mask_to_apicid(cpumask, apicid);
568 free_cpumask_var(cpumask);
573 static int es7000_phys_pkg_id(
int cpuid_apic,
int index_msb)
575 return cpuid_apic >> index_msb;
578 static int probe_es7000(
void)
584 static int es7000_mps_ret;
585 static int es7000_mps_oem_check(
struct mpc_table *mpc,
char *oem,
595 ret = parse_unisys_oem((
char *)oem_table);
598 es7000_mps_ret =
ret;
600 return ret && !es7000_apic_is_cluster();
603 static int es7000_mps_oem_check_cluster(
struct mpc_table *mpc,
char *oem,
606 int ret = es7000_mps_ret;
608 return ret && es7000_apic_is_cluster();
612 static struct apic
__refdata apic_es7000_cluster = {
615 .probe = probe_es7000,
616 .acpi_madt_oem_check = es7000_acpi_madt_oem_check_cluster,
617 .apic_id_valid = default_apic_id_valid,
618 .apic_id_registered = es7000_apic_id_registered,
624 .target_cpus = target_cpus_cluster,
627 .check_apicid_used = es7000_check_apicid_used,
628 .check_apicid_present = es7000_check_apicid_present,
630 .vector_allocation_domain = flat_vector_allocation_domain,
631 .init_apic_ldr = es7000_init_apic_ldr_cluster,
633 .ioapic_phys_id_map = es7000_ioapic_phys_id_map,
634 .setup_apic_routing = es7000_setup_apic_routing,
635 .multi_timer_check =
NULL,
636 .cpu_present_to_apicid = es7000_cpu_present_to_apicid,
637 .apicid_to_cpu_present = es7000_apicid_to_cpu_present,
638 .setup_portio_remap =
NULL,
639 .check_phys_apicid_present = es7000_check_phys_apicid_present,
640 .enable_apic_mode = es7000_enable_apic_mode,
641 .phys_pkg_id = es7000_phys_pkg_id,
642 .mps_oem_check = es7000_mps_oem_check_cluster,
644 .get_apic_id = es7000_get_apic_id,
646 .apic_id_mask = 0xFF << 24,
648 .cpu_mask_to_apicid_and = es7000_cpu_mask_to_apicid_and,
650 .send_IPI_mask = es7000_send_IPI_mask,
651 .send_IPI_mask_allbutself =
NULL,
652 .send_IPI_allbutself = es7000_send_IPI_allbutself,
653 .send_IPI_all = es7000_send_IPI_all,
654 .send_IPI_self = default_send_IPI_self,
656 .wakeup_secondary_cpu = wakeup_secondary_cpu_via_mip,
658 .trampoline_phys_low = 0x467,
659 .trampoline_phys_high = 0x469,
661 .wait_for_init_deassert =
NULL,
664 .smp_callin_clear_local_apic =
NULL,
665 .inquire_remote_apic = default_inquire_remote_apic,
667 .read = native_apic_mem_read,
668 .write = native_apic_mem_write,
669 .eoi_write = native_apic_mem_write,
675 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
678 static struct apic
__refdata apic_es7000 = {
681 .probe = probe_es7000,
682 .acpi_madt_oem_check = es7000_acpi_madt_oem_check,
683 .apic_id_valid = default_apic_id_valid,
684 .apic_id_registered = es7000_apic_id_registered,
690 .target_cpus = es7000_target_cpus,
693 .check_apicid_used = es7000_check_apicid_used,
694 .check_apicid_present = es7000_check_apicid_present,
696 .vector_allocation_domain = flat_vector_allocation_domain,
697 .init_apic_ldr = es7000_init_apic_ldr,
699 .ioapic_phys_id_map = es7000_ioapic_phys_id_map,
700 .setup_apic_routing = es7000_setup_apic_routing,
701 .multi_timer_check =
NULL,
702 .cpu_present_to_apicid = es7000_cpu_present_to_apicid,
703 .apicid_to_cpu_present = es7000_apicid_to_cpu_present,
704 .setup_portio_remap =
NULL,
705 .check_phys_apicid_present = es7000_check_phys_apicid_present,
706 .enable_apic_mode = es7000_enable_apic_mode,
707 .phys_pkg_id = es7000_phys_pkg_id,
708 .mps_oem_check = es7000_mps_oem_check,
710 .get_apic_id = es7000_get_apic_id,
712 .apic_id_mask = 0xFF << 24,
714 .cpu_mask_to_apicid_and = es7000_cpu_mask_to_apicid_and,
716 .send_IPI_mask = es7000_send_IPI_mask,
717 .send_IPI_mask_allbutself =
NULL,
718 .send_IPI_allbutself = es7000_send_IPI_allbutself,
719 .send_IPI_all = es7000_send_IPI_all,
720 .send_IPI_self = default_send_IPI_self,
722 .trampoline_phys_low = 0x467,
723 .trampoline_phys_high = 0x469,
725 .wait_for_init_deassert = es7000_wait_for_init_deassert,
728 .smp_callin_clear_local_apic =
NULL,
729 .inquire_remote_apic = default_inquire_remote_apic,
731 .read = native_apic_mem_read,
732 .write = native_apic_mem_write,
733 .eoi_write = native_apic_mem_write,
739 .x86_32_early_logical_apicid = es7000_early_logical_apicid,