2 * Written by: Garry Forsgren, Unisys Corporation
3 * Natalie Protasevich, Unisys Corporation
5 * This file contains the code to configure and interface
6 * with Unisys ES7000 series hardware system manager.
8 * Copyright (c) 2003 Unisys Corporation.
9 * Copyright (C) 2009, Red Hat, Inc., Ingo Molnar
11 * All Rights Reserved.
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
17 * This program is distributed in the hope that it would be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write the Free Software Foundation, Inc., 59
23 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
25 * Contact information: Unisys Corporation, Township Line & Union Meeting
26 * Roads-A, Unisys Way, Blue Bell, Pennsylvania, 19424, or:
28 * http://www.unisys.com
30 #include <linux/notifier.h>
31 #include <linux/spinlock.h>
32 #include <linux/cpumask.h>
33 #include <linux/threads.h>
34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/reboot.h>
37 #include <linux/string.h>
38 #include <linux/types.h>
39 #include <linux/errno.h>
40 #include <linux/acpi.h>
41 #include <linux/init.h>
42 #include <linux/nmi.h>
43 #include <linux/smp.h>
46 #include <asm/apicdef.h>
47 #include <asm/atomic.h>
48 #include <asm/fixmap.h>
49 #include <asm/mpspec.h>
50 #include <asm/setup.h>
59 #define ES7000_CLASSIC 1
60 #define ES7000_ZORRO 2
63 #define MIP_PSAI_REG 4
66 #define MIP_SPIN 0xf0000
67 #define MIP_VALID 0x0100000000000000ULL
68 #define MIP_SW_APIC 0x1020b
70 #define MIP_PORT(val) ((val >> 32) & 0xffff)
72 #define MIP_RD_LO(val) (val & 0xffffffff)
75 unsigned long long off_0x00
;
76 unsigned long long off_0x08
;
77 unsigned long long off_0x10
;
78 unsigned long long off_0x18
;
79 unsigned long long off_0x20
;
80 unsigned long long off_0x28
;
81 unsigned long long off_0x30
;
82 unsigned long long off_0x38
;
86 unsigned long long mip_info
;
87 unsigned long long delivery_info
;
88 unsigned long long host_reg
;
89 unsigned long long mip_reg
;
93 unsigned long long entry_type
;
94 unsigned long long addr
;
95 unsigned long long bep_addr
;
100 struct es7000_oem_table
{
101 struct acpi_table_header Header
;
106 static unsigned long oem_addrX
;
107 static unsigned long oem_size
;
115 static volatile unsigned long *psai
;
116 static struct mip_reg
*mip_reg
;
117 static struct mip_reg
*host_reg
;
119 static unsigned long mip_addr
;
120 static unsigned long host_addr
;
125 * GSI override for ES7000 platforms.
128 static unsigned int base
;
131 es7000_rename_gsi(int ioapic
, int gsi
)
133 if (es7000_plat
== ES7000_ZORRO
)
138 for (i
= 0; i
< nr_ioapics
; i
++)
139 base
+= nr_ioapic_registers
[i
];
142 if (!ioapic
&& (gsi
< 16))
148 static int wakeup_secondary_cpu_via_mip(int cpu
, unsigned long eip
)
150 unsigned long vect
= 0, psaival
= 0;
155 vect
= ((unsigned long)__pa(eip
)/0x1000) << 16;
156 psaival
= (0x1000000 | vect
| cpu
);
158 while (*psai
& 0x1000000)
166 static int __init
es7000_apic_is_cluster(void)
169 if (boot_cpu_data
.x86
== 6 &&
170 (boot_cpu_data
.x86_model
>= 7 || boot_cpu_data
.x86_model
<= 11))
176 static void __init
setup_unisys(void)
179 * Determine the generation of the ES7000 currently running.
181 * es7000_plat = 1 if the machine is a 5xx ES7000 box
182 * es7000_plat = 2 if the machine is a x86_64 ES7000 box
185 if (!(boot_cpu_data
.x86
<= 15 && boot_cpu_data
.x86_model
<= 2))
186 es7000_plat
= ES7000_ZORRO
;
188 es7000_plat
= ES7000_CLASSIC
;
189 ioapic_renumber_irq
= es7000_rename_gsi
;
193 * Parse the OEM Table:
195 static int __init
parse_unisys_oem(char *oemptr
)
199 unsigned char type
, size
;
202 struct psai
*psaip
= NULL
;
203 struct mip_reg_info
*mi
;
204 struct mip_reg
*host
, *mip
;
210 for (i
= 0; i
<= 6; i
++) {
216 mi
= (struct mip_reg_info
*)tp
;
217 val
= MIP_RD_LO(mi
->host_reg
);
219 host
= (struct mip_reg
*)val
;
220 host_reg
= __va(host
);
221 val
= MIP_RD_LO(mi
->mip_reg
);
222 mip_port
= MIP_PORT(mi
->mip_info
);
224 mip
= (struct mip_reg
*)val
;
226 pr_debug("es7000_mipcfg: host_reg = 0x%lx \n",
227 (unsigned long)host_reg
);
228 pr_debug("es7000_mipcfg: mip_reg = 0x%lx \n",
229 (unsigned long)mip_reg
);
233 psaip
= (struct psai
*)tp
;
236 psai
= __va(psaip
->addr
);
249 es7000_plat
= NON_UNISYS
;
257 static int __init
find_unisys_acpi_oem_table(unsigned long *oem_addr
)
259 struct acpi_table_header
*header
= NULL
;
260 struct es7000_oem_table
*table
;
266 ret
= acpi_get_table_with_size("OEM1", i
++, &header
, &tbl_size
);
267 if (!ACPI_SUCCESS(ret
))
270 if (!memcmp((char *) &header
->oem_id
, "UNISYS", 6))
273 early_acpi_os_unmap_memory(header
, tbl_size
);
276 table
= (void *)header
;
278 oem_addrX
= table
->OEMTableAddr
;
279 oem_size
= table
->OEMTableSize
;
281 early_acpi_os_unmap_memory(header
, tbl_size
);
283 *oem_addr
= (unsigned long)__acpi_map_table(oem_addrX
, oem_size
);
288 static void __init
unmap_unisys_acpi_oem_table(unsigned long oem_addr
)
293 __acpi_unmap_table((char *)oem_addr
, oem_size
);
296 static int es7000_check_dsdt(void)
298 struct acpi_table_header header
;
300 if (ACPI_SUCCESS(acpi_get_table_header(ACPI_SIG_DSDT
, 0, &header
)) &&
301 !strncmp(header
.oem_id
, "UNISYS", 6))
306 static int __initdata es7000_acpi_ret
;
308 /* Hook from generic ACPI tables.c */
309 static int __init
es7000_acpi_madt_oem_check(char *oem_id
, char *oem_table_id
)
311 unsigned long oem_addr
= 0;
315 /* check dsdt at first to avoid clear fix_map for oem_addr */
316 check_dsdt
= es7000_check_dsdt();
318 if (!find_unisys_acpi_oem_table(&oem_addr
)) {
320 ret
= parse_unisys_oem((char *)oem_addr
);
326 * we need to unmap it
328 unmap_unisys_acpi_oem_table(oem_addr
);
331 es7000_acpi_ret
= ret
;
333 return ret
&& !es7000_apic_is_cluster();
335 static int __init
es7000_acpi_madt_oem_check_cluster(char *oem_id
,
338 int ret
= es7000_acpi_ret
;
340 return ret
&& es7000_apic_is_cluster();
343 #else /* !CONFIG_ACPI: */
344 static int __init
es7000_acpi_madt_oem_check(char *oem_id
, char *oem_table_id
)
348 #endif /* !CONFIG_ACPI */
350 static void es7000_spin(int n
)
359 es7000_mip_write(struct mip_reg
*mip_reg
)
365 while ((host_reg
->off_0x38
& MIP_VALID
) != 0) {
367 WARN(1, "Timeout waiting for Host Valid Flag\n");
370 es7000_spin(MIP_SPIN
);
373 memcpy(host_reg
, mip_reg
, sizeof(struct mip_reg
));
378 while ((mip_reg
->off_0x38
& MIP_VALID
) == 0) {
380 WARN(1, "Timeout waiting for MIP Valid Flag\n");
383 es7000_spin(MIP_SPIN
);
386 status
= (mip_reg
->off_0x00
& 0xffff0000000000ULL
) >> 48;
387 mip_reg
->off_0x38
&= ~MIP_VALID
;
392 static void __init
es7000_enable_apic_mode(void)
394 struct mip_reg es7000_mip_reg
;
400 printk(KERN_INFO
"ES7000: Enabling APIC mode.\n");
401 memset(&es7000_mip_reg
, 0, sizeof(struct mip_reg
));
402 es7000_mip_reg
.off_0x00
= MIP_SW_APIC
;
403 es7000_mip_reg
.off_0x38
= MIP_VALID
;
405 while ((mip_status
= es7000_mip_write(&es7000_mip_reg
)) != 0)
406 WARN(1, "Command failed, status = %x\n", mip_status
);
409 static void es7000_vector_allocation_domain(int cpu
, cpumask_t
*retmask
)
411 /* Careful. Some cpus do not strictly honor the set of cpus
412 * specified in the interrupt destination when using lowest
413 * priority interrupt delivery mode.
415 * In particular there was a hyperthreading cpu observed to
416 * deliver interrupts to the wrong hyperthread when only one
417 * hyperthread was specified in the interrupt desitination.
419 *retmask
= (cpumask_t
){ { [0] = APIC_ALL_CPUS
, } };
423 static void es7000_wait_for_init_deassert(atomic_t
*deassert
)
425 while (!atomic_read(deassert
))
429 static unsigned int es7000_get_apic_id(unsigned long x
)
431 return (x
>> 24) & 0xFF;
434 static void es7000_send_IPI_mask(const struct cpumask
*mask
, int vector
)
436 default_send_IPI_mask_sequence_phys(mask
, vector
);
439 static void es7000_send_IPI_allbutself(int vector
)
441 default_send_IPI_mask_allbutself_phys(cpu_online_mask
, vector
);
444 static void es7000_send_IPI_all(int vector
)
446 es7000_send_IPI_mask(cpu_online_mask
, vector
);
449 static int es7000_apic_id_registered(void)
454 static const cpumask_t
*target_cpus_cluster(void)
456 return &CPU_MASK_ALL
;
459 static const cpumask_t
*es7000_target_cpus(void)
461 return &cpumask_of_cpu(smp_processor_id());
465 es7000_check_apicid_used(physid_mask_t bitmap
, int apicid
)
469 static unsigned long es7000_check_apicid_present(int bit
)
471 return physid_isset(bit
, phys_cpu_present_map
);
474 static unsigned long calculate_ldr(int cpu
)
476 unsigned long id
= per_cpu(x86_bios_cpu_apicid
, cpu
);
478 return SET_APIC_LOGICAL_ID(id
);
482 * Set up the logical destination ID.
484 * Intel recommends to set DFR, LdR and TPR before enabling
485 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
486 * document number 292116). So here it goes...
488 static void es7000_init_apic_ldr_cluster(void)
491 int cpu
= smp_processor_id();
493 apic_write(APIC_DFR
, APIC_DFR_CLUSTER
);
494 val
= calculate_ldr(cpu
);
495 apic_write(APIC_LDR
, val
);
498 static void es7000_init_apic_ldr(void)
501 int cpu
= smp_processor_id();
503 apic_write(APIC_DFR
, APIC_DFR_FLAT
);
504 val
= calculate_ldr(cpu
);
505 apic_write(APIC_LDR
, val
);
508 static void es7000_setup_apic_routing(void)
510 int apic
= per_cpu(x86_bios_cpu_apicid
, smp_processor_id());
513 "Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
514 (apic_version
[apic
] == 0x14) ?
515 "Physical Cluster" : "Logical Cluster",
516 nr_ioapics
, cpus_addr(*es7000_target_cpus())[0]);
519 static int es7000_apicid_to_node(int logical_apicid
)
525 static int es7000_cpu_present_to_apicid(int mps_cpu
)
528 return boot_cpu_physical_apicid
;
529 else if (mps_cpu
< nr_cpu_ids
)
530 return per_cpu(x86_bios_cpu_apicid
, mps_cpu
);
537 static physid_mask_t
es7000_apicid_to_cpu_present(int phys_apicid
)
541 mask
= physid_mask_of_physid(cpu_id
);
547 /* Mapping from cpu number to logical apicid */
548 static int es7000_cpu_to_logical_apicid(int cpu
)
551 if (cpu
>= nr_cpu_ids
)
553 return cpu_2_logical_apicid
[cpu
];
555 return logical_smp_processor_id();
559 static physid_mask_t
es7000_ioapic_phys_id_map(physid_mask_t phys_map
)
561 /* For clustered we don't have a good way to do this yet - hack */
562 return physids_promote(0xff);
565 static int es7000_check_phys_apicid_present(int cpu_physical_apicid
)
567 boot_cpu_physical_apicid
= read_apic_id();
572 es7000_cpu_mask_to_apicid_cluster(const struct cpumask
*cpumask
)
579 num_bits_set
= cpumask_weight(cpumask
);
580 /* Return id to all */
581 if (num_bits_set
== nr_cpu_ids
)
584 * The cpus in the mask must all be on the apic cluster. If are not
585 * on the same apicid cluster return default value of target_cpus():
587 cpu
= cpumask_first(cpumask
);
588 apicid
= es7000_cpu_to_logical_apicid(cpu
);
590 while (cpus_found
< num_bits_set
) {
591 if (cpumask_test_cpu(cpu
, cpumask
)) {
592 int new_apicid
= es7000_cpu_to_logical_apicid(cpu
);
594 if (APIC_CLUSTER(apicid
) != APIC_CLUSTER(new_apicid
)) {
595 WARN(1, "Not a valid mask!");
607 static unsigned int es7000_cpu_mask_to_apicid(const cpumask_t
*cpumask
)
614 num_bits_set
= cpus_weight(*cpumask
);
615 /* Return id to all */
616 if (num_bits_set
== nr_cpu_ids
)
617 return es7000_cpu_to_logical_apicid(0);
619 * The cpus in the mask must all be on the apic cluster. If are not
620 * on the same apicid cluster return default value of target_cpus():
622 cpu
= first_cpu(*cpumask
);
623 apicid
= es7000_cpu_to_logical_apicid(cpu
);
624 while (cpus_found
< num_bits_set
) {
625 if (cpu_isset(cpu
, *cpumask
)) {
626 int new_apicid
= es7000_cpu_to_logical_apicid(cpu
);
628 if (APIC_CLUSTER(apicid
) != APIC_CLUSTER(new_apicid
)) {
629 printk("%s: Not a valid mask!\n", __func__
);
631 return es7000_cpu_to_logical_apicid(0);
642 es7000_cpu_mask_to_apicid_and(const struct cpumask
*inmask
,
643 const struct cpumask
*andmask
)
645 int apicid
= es7000_cpu_to_logical_apicid(0);
646 cpumask_var_t cpumask
;
648 if (!alloc_cpumask_var(&cpumask
, GFP_ATOMIC
))
651 cpumask_and(cpumask
, inmask
, andmask
);
652 cpumask_and(cpumask
, cpumask
, cpu_online_mask
);
653 apicid
= es7000_cpu_mask_to_apicid(cpumask
);
655 free_cpumask_var(cpumask
);
660 static int es7000_phys_pkg_id(int cpuid_apic
, int index_msb
)
662 return cpuid_apic
>> index_msb
;
665 static int probe_es7000(void)
667 /* probed later in mptable/ACPI hooks */
671 static int __initdata es7000_mps_ret
;
673 es7000_mps_oem_check(struct mpc_table
*mpc
, char *oem
, char *productid
)
678 struct mpc_oemtable
*oem_table
=
679 (struct mpc_oemtable
*)mpc
->oemptr
;
681 if (!strncmp(oem
, "UNISYS", 6))
682 ret
= parse_unisys_oem((char *)oem_table
);
685 es7000_mps_ret
= ret
;
687 return ret
&& !es7000_apic_is_cluster();
691 es7000_mps_oem_check_cluster(struct mpc_table
*mpc
, char *oem
, char *productid
)
693 int ret
= es7000_mps_ret
;
695 return ret
&& es7000_apic_is_cluster();
698 struct apic apic_es7000_cluster
= {
701 .probe
= probe_es7000
,
702 .acpi_madt_oem_check
= es7000_acpi_madt_oem_check_cluster
,
703 .apic_id_registered
= es7000_apic_id_registered
,
705 .irq_delivery_mode
= dest_LowestPrio
,
706 /* logical delivery broadcast to all procs: */
709 .target_cpus
= target_cpus_cluster
,
712 .check_apicid_used
= es7000_check_apicid_used
,
713 .check_apicid_present
= es7000_check_apicid_present
,
715 .vector_allocation_domain
= es7000_vector_allocation_domain
,
716 .init_apic_ldr
= es7000_init_apic_ldr_cluster
,
718 .ioapic_phys_id_map
= es7000_ioapic_phys_id_map
,
719 .setup_apic_routing
= es7000_setup_apic_routing
,
720 .multi_timer_check
= NULL
,
721 .apicid_to_node
= es7000_apicid_to_node
,
722 .cpu_to_logical_apicid
= es7000_cpu_to_logical_apicid
,
723 .cpu_present_to_apicid
= es7000_cpu_present_to_apicid
,
724 .apicid_to_cpu_present
= es7000_apicid_to_cpu_present
,
725 .setup_portio_remap
= NULL
,
726 .check_phys_apicid_present
= es7000_check_phys_apicid_present
,
727 .enable_apic_mode
= es7000_enable_apic_mode
,
728 .phys_pkg_id
= es7000_phys_pkg_id
,
729 .mps_oem_check
= es7000_mps_oem_check_cluster
,
731 .get_apic_id
= es7000_get_apic_id
,
733 .apic_id_mask
= 0xFF << 24,
735 .cpu_mask_to_apicid
= es7000_cpu_mask_to_apicid_cluster
,
736 .cpu_mask_to_apicid_and
= es7000_cpu_mask_to_apicid_and
,
738 .send_IPI_mask
= es7000_send_IPI_mask
,
739 .send_IPI_mask_allbutself
= NULL
,
740 .send_IPI_allbutself
= es7000_send_IPI_allbutself
,
741 .send_IPI_all
= es7000_send_IPI_all
,
742 .send_IPI_self
= default_send_IPI_self
,
744 .wakeup_cpu
= wakeup_secondary_cpu_via_mip
,
746 .trampoline_phys_low
= 0x467,
747 .trampoline_phys_high
= 0x469,
749 .wait_for_init_deassert
= NULL
,
751 /* Nothing to do for most platforms, since cleared by the INIT cycle: */
752 .smp_callin_clear_local_apic
= NULL
,
753 .inquire_remote_apic
= default_inquire_remote_apic
,
755 .read
= native_apic_mem_read
,
756 .write
= native_apic_mem_write
,
757 .icr_read
= native_apic_icr_read
,
758 .icr_write
= native_apic_icr_write
,
759 .wait_icr_idle
= native_apic_wait_icr_idle
,
760 .safe_wait_icr_idle
= native_safe_apic_wait_icr_idle
,
763 struct apic apic_es7000
= {
766 .probe
= probe_es7000
,
767 .acpi_madt_oem_check
= es7000_acpi_madt_oem_check
,
768 .apic_id_registered
= es7000_apic_id_registered
,
770 .irq_delivery_mode
= dest_Fixed
,
771 /* phys delivery to target CPUs: */
774 .target_cpus
= es7000_target_cpus
,
777 .check_apicid_used
= es7000_check_apicid_used
,
778 .check_apicid_present
= es7000_check_apicid_present
,
780 .vector_allocation_domain
= es7000_vector_allocation_domain
,
781 .init_apic_ldr
= es7000_init_apic_ldr
,
783 .ioapic_phys_id_map
= es7000_ioapic_phys_id_map
,
784 .setup_apic_routing
= es7000_setup_apic_routing
,
785 .multi_timer_check
= NULL
,
786 .apicid_to_node
= es7000_apicid_to_node
,
787 .cpu_to_logical_apicid
= es7000_cpu_to_logical_apicid
,
788 .cpu_present_to_apicid
= es7000_cpu_present_to_apicid
,
789 .apicid_to_cpu_present
= es7000_apicid_to_cpu_present
,
790 .setup_portio_remap
= NULL
,
791 .check_phys_apicid_present
= es7000_check_phys_apicid_present
,
792 .enable_apic_mode
= es7000_enable_apic_mode
,
793 .phys_pkg_id
= es7000_phys_pkg_id
,
794 .mps_oem_check
= es7000_mps_oem_check
,
796 .get_apic_id
= es7000_get_apic_id
,
798 .apic_id_mask
= 0xFF << 24,
800 .cpu_mask_to_apicid
= es7000_cpu_mask_to_apicid
,
801 .cpu_mask_to_apicid_and
= es7000_cpu_mask_to_apicid_and
,
803 .send_IPI_mask
= es7000_send_IPI_mask
,
804 .send_IPI_mask_allbutself
= NULL
,
805 .send_IPI_allbutself
= es7000_send_IPI_allbutself
,
806 .send_IPI_all
= es7000_send_IPI_all
,
807 .send_IPI_self
= default_send_IPI_self
,
809 .wakeup_cpu
= wakeup_secondary_cpu_via_init
,
811 .trampoline_phys_low
= 0x467,
812 .trampoline_phys_high
= 0x469,
814 .wait_for_init_deassert
= es7000_wait_for_init_deassert
,
816 /* Nothing to do for most platforms, since cleared by the INIT cycle: */
817 .smp_callin_clear_local_apic
= NULL
,
818 .inquire_remote_apic
= default_inquire_remote_apic
,
820 .read
= native_apic_mem_read
,
821 .write
= native_apic_mem_write
,
822 .icr_read
= native_apic_icr_read
,
823 .icr_write
= native_apic_icr_write
,
824 .wait_icr_idle
= native_apic_wait_icr_idle
,
825 .safe_wait_icr_idle
= native_safe_apic_wait_icr_idle
,