2 * Written by: Garry Forsgren, Unisys Corporation
3 * Natalie Protasevich, Unisys Corporation
4 * This file contains the code to configure and interface
5 * with Unisys ES7000 series hardware system manager.
7 * Copyright (c) 2003 Unisys Corporation. All Rights Reserved.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it would be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write the Free Software Foundation, Inc., 59
19 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
21 * Contact information: Unisys Corporation, Township Line & Union Meeting
22 * Roads-A, Unisys Way, Blue Bell, Pennsylvania, 19424, or:
24 * http://www.unisys.com
27 #include <linux/notifier.h>
28 #include <linux/spinlock.h>
29 #include <linux/cpumask.h>
30 #include <linux/threads.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/reboot.h>
34 #include <linux/string.h>
35 #include <linux/types.h>
36 #include <linux/errno.h>
37 #include <linux/acpi.h>
38 #include <linux/init.h>
39 #include <linux/smp.h>
41 #include <asm/apicdef.h>
42 #include <asm/atomic.h>
43 #include <asm/fixmap.h>
44 #include <asm/mpspec.h>
45 #include <asm/setup.h>
57 #define ES7000_CLASSIC 1
58 #define ES7000_ZORRO 2
61 #define MIP_PSAI_REG 4
64 #define MIP_SPIN 0xf0000
65 #define MIP_VALID 0x0100000000000000ULL
67 #define MIP_PORT(val) ((val >> 32) & 0xffff)
69 #define MIP_RD_LO(val) (val & 0xffffffff)
72 unsigned long long mip_info
;
73 unsigned long long delivery_info
;
74 unsigned long long host_reg
;
75 unsigned long long mip_reg
;
81 unsigned char part_id
;
82 unsigned char apic_mode
;
90 unsigned long long entry_type
;
91 unsigned long long addr
;
92 unsigned long long bep_addr
;
95 struct es7000_mem_info
{
98 unsigned char resv
[6];
99 unsigned long long start
;
100 unsigned long long size
;
103 struct es7000_oem_table
{
104 unsigned long long hdr
;
105 struct mip_reg_info mip
;
106 struct part_info pif
;
107 struct es7000_mem_info shm
;
114 struct acpi_table_header Header
;
119 extern int find_unisys_acpi_oem_table(unsigned long *oem_addr
);
120 extern void unmap_unisys_acpi_oem_table(unsigned long oem_addr
);
124 unsigned long long off_0x00
;
125 unsigned long long off_0x08
;
126 unsigned long long off_0x10
;
127 unsigned long long off_0x18
;
128 unsigned long long off_0x20
;
129 unsigned long long off_0x28
;
130 unsigned long long off_0x30
;
131 unsigned long long off_0x38
;
134 #define MIP_SW_APIC 0x1020b
135 #define MIP_FUNC(VALUE) (VALUE & 0xff)
137 #define APIC_DFR_VALUE_CLUSTER (APIC_DFR_CLUSTER)
138 #define INT_DELIVERY_MODE_CLUSTER (dest_LowestPrio)
139 #define INT_DEST_MODE_CLUSTER (1) /* logical delivery broadcast to all procs */
141 #define APIC_DFR_VALUE (APIC_DFR_FLAT)
143 extern void es7000_enable_apic_mode(void);
144 extern int parse_unisys_oem (char *oemptr
);
145 extern int find_unisys_acpi_oem_table(unsigned long *oem_addr
);
146 extern void unmap_unisys_acpi_oem_table(unsigned long oem_addr
);
147 extern void setup_unisys(void);
149 #define apicid_cluster(apicid) (apicid & 0xF0)
155 static volatile unsigned long *psai
= NULL
;
156 static struct mip_reg
*mip_reg
;
157 static struct mip_reg
*host_reg
;
159 static unsigned long mip_addr
, host_addr
;
164 * GSI override for ES7000 platforms.
167 static unsigned int base
;
170 es7000_rename_gsi(int ioapic
, int gsi
)
172 if (es7000_plat
== ES7000_ZORRO
)
177 for (i
= 0; i
< nr_ioapics
; i
++)
178 base
+= nr_ioapic_registers
[i
];
181 if (!ioapic
&& (gsi
< 16))
187 static int wakeup_secondary_cpu_via_mip(int cpu
, unsigned long eip
)
189 unsigned long vect
= 0, psaival
= 0;
194 vect
= ((unsigned long)__pa(eip
)/0x1000) << 16;
195 psaival
= (0x1000000 | vect
| cpu
);
197 while (*psai
& 0x1000000)
205 static int __init
es7000_update_genapic(void)
207 apic
->wakeup_cpu
= wakeup_secondary_cpu_via_mip
;
210 if (boot_cpu_data
.x86
== 6 &&
211 (boot_cpu_data
.x86_model
>= 7 || boot_cpu_data
.x86_model
<= 11)) {
212 es7000_update_genapic_to_cluster();
213 apic
->wait_for_init_deassert
= NULL
;
214 apic
->wakeup_cpu
= wakeup_secondary_cpu_via_mip
;
220 void __init
setup_unisys(void)
223 * Determine the generation of the ES7000 currently running.
225 * es7000_plat = 1 if the machine is a 5xx ES7000 box
226 * es7000_plat = 2 if the machine is a x86_64 ES7000 box
229 if (!(boot_cpu_data
.x86
<= 15 && boot_cpu_data
.x86_model
<= 2))
230 es7000_plat
= ES7000_ZORRO
;
232 es7000_plat
= ES7000_CLASSIC
;
233 ioapic_renumber_irq
= es7000_rename_gsi
;
235 x86_quirks
->update_genapic
= es7000_update_genapic
;
239 * Parse the OEM Table
242 int __init
parse_unisys_oem (char *oemptr
)
246 unsigned char type
, size
;
249 struct psai
*psaip
= NULL
;
250 struct mip_reg_info
*mi
;
251 struct mip_reg
*host
, *mip
;
257 for (i
=0; i
<= 6; i
++) {
263 mi
= (struct mip_reg_info
*)tp
;
264 val
= MIP_RD_LO(mi
->host_reg
);
266 host
= (struct mip_reg
*)val
;
267 host_reg
= __va(host
);
268 val
= MIP_RD_LO(mi
->mip_reg
);
269 mip_port
= MIP_PORT(mi
->mip_info
);
271 mip
= (struct mip_reg
*)val
;
273 pr_debug("es7000_mipcfg: host_reg = 0x%lx \n",
274 (unsigned long)host_reg
);
275 pr_debug("es7000_mipcfg: mip_reg = 0x%lx \n",
276 (unsigned long)mip_reg
);
280 psaip
= (struct psai
*)tp
;
283 psai
= __va(psaip
->addr
);
296 es7000_plat
= NON_UNISYS
;
305 static unsigned long oem_addrX
;
306 static unsigned long oem_size
;
308 int __init
find_unisys_acpi_oem_table(unsigned long *oem_addr
)
310 struct acpi_table_header
*header
= NULL
;
314 while (ACPI_SUCCESS(acpi_get_table_with_size("OEM1", i
++, &header
, &tbl_size
))) {
315 if (!memcmp((char *) &header
->oem_id
, "UNISYS", 6)) {
316 struct oem_table
*t
= (struct oem_table
*)header
;
318 oem_addrX
= t
->OEMTableAddr
;
319 oem_size
= t
->OEMTableSize
;
320 early_acpi_os_unmap_memory(header
, tbl_size
);
322 *oem_addr
= (unsigned long)__acpi_map_table(oem_addrX
,
326 early_acpi_os_unmap_memory(header
, tbl_size
);
331 void __init
unmap_unisys_acpi_oem_table(unsigned long oem_addr
)
336 __acpi_unmap_table((char *)oem_addr
, oem_size
);
340 static void es7000_spin(int n
)
349 es7000_mip_write(struct mip_reg
*mip_reg
)
355 while ((host_reg
->off_0x38
& MIP_VALID
) != 0) {
357 printk("es7000_mip_write: Timeout waiting for Host Valid Flag");
360 es7000_spin(MIP_SPIN
);
363 memcpy(host_reg
, mip_reg
, sizeof(struct mip_reg
));
368 while ((mip_reg
->off_0x38
& MIP_VALID
) == 0) {
370 printk("es7000_mip_write: Timeout waiting for MIP Valid Flag");
373 es7000_spin(MIP_SPIN
);
376 status
= (mip_reg
->off_0x00
& 0xffff0000000000ULL
) >> 48;
377 mip_reg
->off_0x38
&= ~MIP_VALID
;
382 void __init
es7000_enable_apic_mode(void)
384 struct mip_reg es7000_mip_reg
;
390 printk("ES7000: Enabling APIC mode.\n");
391 memset(&es7000_mip_reg
, 0, sizeof(struct mip_reg
));
392 es7000_mip_reg
.off_0x00
= MIP_SW_APIC
;
393 es7000_mip_reg
.off_0x38
= MIP_VALID
;
395 while ((mip_status
= es7000_mip_write(&es7000_mip_reg
)) != 0) {
396 printk("es7000_enable_apic_mode: command failed, status = %x\n",
401 static void es7000_vector_allocation_domain(int cpu
, cpumask_t
*retmask
)
403 /* Careful. Some cpus do not strictly honor the set of cpus
404 * specified in the interrupt destination when using lowest
405 * priority interrupt delivery mode.
407 * In particular there was a hyperthreading cpu observed to
408 * deliver interrupts to the wrong hyperthread when only one
409 * hyperthread was specified in the interrupt desitination.
411 *retmask
= (cpumask_t
){ { [0] = APIC_ALL_CPUS
, } };
415 static void es7000_wait_for_init_deassert(atomic_t
*deassert
)
417 #ifndef CONFIG_ES7000_CLUSTERED_APIC
418 while (!atomic_read(deassert
))
424 static unsigned int es7000_get_apic_id(unsigned long x
)
426 return (x
>> 24) & 0xFF;
430 static int es7000_check_dsdt(void)
432 struct acpi_table_header header
;
434 if (ACPI_SUCCESS(acpi_get_table_header(ACPI_SIG_DSDT
, 0, &header
)) &&
435 !strncmp(header
.oem_id
, "UNISYS", 6))
441 static void es7000_send_IPI_mask(const struct cpumask
*mask
, int vector
)
443 default_send_IPI_mask_sequence_phys(mask
, vector
);
446 static void es7000_send_IPI_allbutself(int vector
)
448 default_send_IPI_mask_allbutself_phys(cpu_online_mask
, vector
);
451 static void es7000_send_IPI_all(int vector
)
453 es7000_send_IPI_mask(cpu_online_mask
, vector
);
456 static int es7000_apic_id_registered(void)
461 static const cpumask_t
*target_cpus_cluster(void)
463 return &CPU_MASK_ALL
;
466 static const cpumask_t
*es7000_target_cpus(void)
468 return &cpumask_of_cpu(smp_processor_id());
472 es7000_check_apicid_used(physid_mask_t bitmap
, int apicid
)
476 static unsigned long es7000_check_apicid_present(int bit
)
478 return physid_isset(bit
, phys_cpu_present_map
);
481 static unsigned long calculate_ldr(int cpu
)
483 unsigned long id
= per_cpu(x86_bios_cpu_apicid
, cpu
);
485 return SET_APIC_LOGICAL_ID(id
);
489 * Set up the logical destination ID.
491 * Intel recommends to set DFR, LdR and TPR before enabling
492 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
493 * document number 292116). So here it goes...
495 static void es7000_init_apic_ldr_cluster(void)
498 int cpu
= smp_processor_id();
500 apic_write(APIC_DFR
, APIC_DFR_VALUE_CLUSTER
);
501 val
= calculate_ldr(cpu
);
502 apic_write(APIC_LDR
, val
);
505 static void es7000_init_apic_ldr(void)
508 int cpu
= smp_processor_id();
510 apic_write(APIC_DFR
, APIC_DFR_VALUE
);
511 val
= calculate_ldr(cpu
);
512 apic_write(APIC_LDR
, val
);
515 static void es7000_setup_apic_routing(void)
517 int apic
= per_cpu(x86_bios_cpu_apicid
, smp_processor_id());
518 printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
519 (apic_version
[apic
] == 0x14) ?
520 "Physical Cluster" : "Logical Cluster",
521 nr_ioapics
, cpus_addr(*es7000_target_cpus())[0]);
524 static int es7000_apicid_to_node(int logical_apicid
)
530 static int es7000_cpu_present_to_apicid(int mps_cpu
)
533 return boot_cpu_physical_apicid
;
534 else if (mps_cpu
< nr_cpu_ids
)
535 return per_cpu(x86_bios_cpu_apicid
, mps_cpu
);
540 static physid_mask_t
es7000_apicid_to_cpu_present(int phys_apicid
)
545 mask
= physid_mask_of_physid(id
);
551 /* Mapping from cpu number to logical apicid */
552 static int es7000_cpu_to_logical_apicid(int cpu
)
555 if (cpu
>= nr_cpu_ids
)
557 return cpu_2_logical_apicid
[cpu
];
559 return logical_smp_processor_id();
563 static physid_mask_t
es7000_ioapic_phys_id_map(physid_mask_t phys_map
)
565 /* For clustered we don't have a good way to do this yet - hack */
566 return physids_promote(0xff);
569 static int es7000_check_phys_apicid_present(int cpu_physical_apicid
)
571 boot_cpu_physical_apicid
= read_apic_id();
576 es7000_cpu_mask_to_apicid_cluster(const struct cpumask
*cpumask
)
583 num_bits_set
= cpumask_weight(cpumask
);
584 /* Return id to all */
585 if (num_bits_set
== nr_cpu_ids
)
588 * The cpus in the mask must all be on the apic cluster. If are not
589 * on the same apicid cluster return default value of target_cpus():
591 cpu
= cpumask_first(cpumask
);
592 apicid
= es7000_cpu_to_logical_apicid(cpu
);
594 while (cpus_found
< num_bits_set
) {
595 if (cpumask_test_cpu(cpu
, cpumask
)) {
596 int new_apicid
= es7000_cpu_to_logical_apicid(cpu
);
598 if (apicid_cluster(apicid
) !=
599 apicid_cluster(new_apicid
)) {
600 printk ("%s: Not a valid mask!\n", __func__
);
612 static unsigned int es7000_cpu_mask_to_apicid(const cpumask_t
*cpumask
)
619 num_bits_set
= cpus_weight(*cpumask
);
620 /* Return id to all */
621 if (num_bits_set
== nr_cpu_ids
)
622 return es7000_cpu_to_logical_apicid(0);
624 * The cpus in the mask must all be on the apic cluster. If are not
625 * on the same apicid cluster return default value of target_cpus():
627 cpu
= first_cpu(*cpumask
);
628 apicid
= es7000_cpu_to_logical_apicid(cpu
);
629 while (cpus_found
< num_bits_set
) {
630 if (cpu_isset(cpu
, *cpumask
)) {
631 int new_apicid
= es7000_cpu_to_logical_apicid(cpu
);
633 if (apicid_cluster(apicid
) !=
634 apicid_cluster(new_apicid
)) {
635 printk ("%s: Not a valid mask!\n", __func__
);
637 return es7000_cpu_to_logical_apicid(0);
648 es7000_cpu_mask_to_apicid_and(const struct cpumask
*inmask
,
649 const struct cpumask
*andmask
)
651 int apicid
= es7000_cpu_to_logical_apicid(0);
652 cpumask_var_t cpumask
;
654 if (!alloc_cpumask_var(&cpumask
, GFP_ATOMIC
))
657 cpumask_and(cpumask
, inmask
, andmask
);
658 cpumask_and(cpumask
, cpumask
, cpu_online_mask
);
659 apicid
= es7000_cpu_mask_to_apicid(cpumask
);
661 free_cpumask_var(cpumask
);
666 static int es7000_phys_pkg_id(int cpuid_apic
, int index_msb
)
668 return cpuid_apic
>> index_msb
;
671 void __init
es7000_update_genapic_to_cluster(void)
673 apic
->target_cpus
= target_cpus_cluster
;
674 apic
->irq_delivery_mode
= INT_DELIVERY_MODE_CLUSTER
;
675 apic
->irq_dest_mode
= INT_DEST_MODE_CLUSTER
;
677 apic
->init_apic_ldr
= es7000_init_apic_ldr_cluster
;
679 apic
->cpu_mask_to_apicid
= es7000_cpu_mask_to_apicid_cluster
;
682 static int probe_es7000(void)
684 /* probed later in mptable/ACPI hooks */
689 es7000_mps_oem_check(struct mpc_table
*mpc
, char *oem
, char *productid
)
692 struct mpc_oemtable
*oem_table
=
693 (struct mpc_oemtable
*)mpc
->oemptr
;
695 if (!strncmp(oem
, "UNISYS", 6))
696 return parse_unisys_oem((char *)oem_table
);
702 /* Hook from generic ACPI tables.c */
703 static int __init
es7000_acpi_madt_oem_check(char *oem_id
, char *oem_table_id
)
705 unsigned long oem_addr
= 0;
709 /* check dsdt at first to avoid clear fix_map for oem_addr */
710 check_dsdt
= es7000_check_dsdt();
712 if (!find_unisys_acpi_oem_table(&oem_addr
)) {
714 ret
= parse_unisys_oem((char *)oem_addr
);
720 * we need to unmap it
722 unmap_unisys_acpi_oem_table(oem_addr
);
727 static int __init
es7000_acpi_madt_oem_check(char *oem_id
, char *oem_table_id
)
734 struct genapic apic_es7000
= {
737 .probe
= probe_es7000
,
738 .acpi_madt_oem_check
= es7000_acpi_madt_oem_check
,
739 .apic_id_registered
= es7000_apic_id_registered
,
741 .irq_delivery_mode
= dest_Fixed
,
742 /* phys delivery to target CPUs: */
745 .target_cpus
= es7000_target_cpus
,
748 .check_apicid_used
= es7000_check_apicid_used
,
749 .check_apicid_present
= es7000_check_apicid_present
,
751 .vector_allocation_domain
= es7000_vector_allocation_domain
,
752 .init_apic_ldr
= es7000_init_apic_ldr
,
754 .ioapic_phys_id_map
= es7000_ioapic_phys_id_map
,
755 .setup_apic_routing
= es7000_setup_apic_routing
,
756 .multi_timer_check
= NULL
,
757 .apicid_to_node
= es7000_apicid_to_node
,
758 .cpu_to_logical_apicid
= es7000_cpu_to_logical_apicid
,
759 .cpu_present_to_apicid
= es7000_cpu_present_to_apicid
,
760 .apicid_to_cpu_present
= es7000_apicid_to_cpu_present
,
761 .setup_portio_remap
= NULL
,
762 .check_phys_apicid_present
= es7000_check_phys_apicid_present
,
763 .enable_apic_mode
= es7000_enable_apic_mode
,
764 .phys_pkg_id
= es7000_phys_pkg_id
,
765 .mps_oem_check
= es7000_mps_oem_check
,
767 .get_apic_id
= es7000_get_apic_id
,
769 .apic_id_mask
= 0xFF << 24,
771 .cpu_mask_to_apicid
= es7000_cpu_mask_to_apicid
,
772 .cpu_mask_to_apicid_and
= es7000_cpu_mask_to_apicid_and
,
774 .send_IPI_mask
= es7000_send_IPI_mask
,
775 .send_IPI_mask_allbutself
= NULL
,
776 .send_IPI_allbutself
= es7000_send_IPI_allbutself
,
777 .send_IPI_all
= es7000_send_IPI_all
,
778 .send_IPI_self
= default_send_IPI_self
,
782 .trampoline_phys_low
= 0x467,
783 .trampoline_phys_high
= 0x469,
785 .wait_for_init_deassert
= es7000_wait_for_init_deassert
,
787 /* Nothing to do for most platforms, since cleared by the INIT cycle: */
788 .smp_callin_clear_local_apic
= NULL
,
789 .store_NMI_vector
= NULL
,
790 .inquire_remote_apic
= default_inquire_remote_apic
,
792 .read
= native_apic_mem_read
,
793 .write
= native_apic_mem_write
,
794 .icr_read
= native_apic_icr_read
,
795 .icr_write
= native_apic_icr_write
,
796 .wait_icr_idle
= native_apic_wait_icr_idle
,
797 .safe_wait_icr_idle
= native_safe_apic_wait_icr_idle
,