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/module.h>
28 #include <linux/types.h>
29 #include <linux/kernel.h>
30 #include <linux/smp.h>
31 #include <linux/string.h>
32 #include <linux/spinlock.h>
33 #include <linux/errno.h>
34 #include <linux/notifier.h>
35 #include <linux/reboot.h>
36 #include <linux/init.h>
37 #include <linux/acpi.h>
41 #include <asm/atomic.h>
42 #include <asm/apicdef.h>
43 #include <asm/genapic.h>
44 #include <asm/setup.h>
51 #define ES7000_CLASSIC 1
52 #define ES7000_ZORRO 2
56 #define MIP_PSAI_REG 4
59 #define MIP_SPIN 0xf0000
60 #define MIP_VALID 0x0100000000000000ULL
61 #define MIP_PORT(VALUE) ((VALUE >> 32) & 0xffff)
63 #define MIP_RD_LO(VALUE) (VALUE & 0xffffffff)
66 unsigned long long mip_info
;
67 unsigned long long delivery_info
;
68 unsigned long long host_reg
;
69 unsigned long long mip_reg
;
75 unsigned char part_id
;
76 unsigned char apic_mode
;
84 unsigned long long entry_type
;
85 unsigned long long addr
;
86 unsigned long long bep_addr
;
89 struct es7000_mem_info
{
92 unsigned char resv
[6];
93 unsigned long long start
;
94 unsigned long long size
;
97 struct es7000_oem_table
{
98 unsigned long long hdr
;
99 struct mip_reg_info mip
;
100 struct part_info pif
;
101 struct es7000_mem_info shm
;
108 struct acpi_table_header Header
;
113 extern int find_unisys_acpi_oem_table(unsigned long *oem_addr
);
114 extern void unmap_unisys_acpi_oem_table(unsigned long oem_addr
);
118 unsigned long long off_0
;
119 unsigned long long off_8
;
120 unsigned long long off_10
;
121 unsigned long long off_18
;
122 unsigned long long off_20
;
123 unsigned long long off_28
;
124 unsigned long long off_30
;
125 unsigned long long off_38
;
128 #define MIP_SW_APIC 0x1020b
129 #define MIP_FUNC(VALUE) (VALUE & 0xff)
135 static volatile unsigned long *psai
= NULL
;
136 static struct mip_reg
*mip_reg
;
137 static struct mip_reg
*host_reg
;
139 static unsigned long mip_addr
, host_addr
;
144 * GSI override for ES7000 platforms.
147 static unsigned int base
;
150 es7000_rename_gsi(int ioapic
, int gsi
)
152 if (es7000_plat
== ES7000_ZORRO
)
157 for (i
= 0; i
< nr_ioapics
; i
++)
158 base
+= nr_ioapic_registers
[i
];
161 if (!ioapic
&& (gsi
< 16))
166 static int wakeup_secondary_cpu_via_mip(int cpu
, unsigned long eip
)
168 unsigned long vect
= 0, psaival
= 0;
173 vect
= ((unsigned long)__pa(eip
)/0x1000) << 16;
174 psaival
= (0x1000000 | vect
| cpu
);
176 while (*psai
& 0x1000000)
184 static int __init
es7000_update_genapic(void)
186 apic
->wakeup_cpu
= wakeup_secondary_cpu_via_mip
;
189 if (boot_cpu_data
.x86
== 6 &&
190 (boot_cpu_data
.x86_model
>= 7 || boot_cpu_data
.x86_model
<= 11)) {
191 es7000_update_genapic_to_cluster();
192 apic
->wait_for_init_deassert
= NULL
;
193 apic
->wakeup_cpu
= wakeup_secondary_cpu_via_mip
;
203 * Determine the generation of the ES7000 currently running.
205 * es7000_plat = 1 if the machine is a 5xx ES7000 box
206 * es7000_plat = 2 if the machine is a x86_64 ES7000 box
209 if (!(boot_cpu_data
.x86
<= 15 && boot_cpu_data
.x86_model
<= 2))
210 es7000_plat
= ES7000_ZORRO
;
212 es7000_plat
= ES7000_CLASSIC
;
213 ioapic_renumber_irq
= es7000_rename_gsi
;
215 x86_quirks
->update_genapic
= es7000_update_genapic
;
219 * Parse the OEM Table
223 parse_unisys_oem (char *oemptr
)
227 unsigned char type
, size
;
230 struct psai
*psaip
= NULL
;
231 struct mip_reg_info
*mi
;
232 struct mip_reg
*host
, *mip
;
238 for (i
=0; i
<= 6; i
++) {
244 mi
= (struct mip_reg_info
*)tp
;
245 val
= MIP_RD_LO(mi
->host_reg
);
247 host
= (struct mip_reg
*)val
;
248 host_reg
= __va(host
);
249 val
= MIP_RD_LO(mi
->mip_reg
);
250 mip_port
= MIP_PORT(mi
->mip_info
);
252 mip
= (struct mip_reg
*)val
;
254 pr_debug("es7000_mipcfg: host_reg = 0x%lx \n",
255 (unsigned long)host_reg
);
256 pr_debug("es7000_mipcfg: mip_reg = 0x%lx \n",
257 (unsigned long)mip_reg
);
261 psaip
= (struct psai
*)tp
;
264 psai
= __va(psaip
->addr
);
277 es7000_plat
= NON_UNISYS
;
284 static unsigned long oem_addrX
;
285 static unsigned long oem_size
;
286 int __init
find_unisys_acpi_oem_table(unsigned long *oem_addr
)
288 struct acpi_table_header
*header
= NULL
;
291 while (ACPI_SUCCESS(acpi_get_table("OEM1", i
++, &header
))) {
292 if (!memcmp((char *) &header
->oem_id
, "UNISYS", 6)) {
293 struct oem_table
*t
= (struct oem_table
*)header
;
295 oem_addrX
= t
->OEMTableAddr
;
296 oem_size
= t
->OEMTableSize
;
298 *oem_addr
= (unsigned long)__acpi_map_table(oem_addrX
,
306 void __init
unmap_unisys_acpi_oem_table(unsigned long oem_addr
)
321 es7000_mip_write(struct mip_reg
*mip_reg
)
327 while (((unsigned long long)host_reg
->off_38
&
328 (unsigned long long)MIP_VALID
) != 0) {
330 printk("es7000_mip_write: Timeout waiting for Host Valid Flag");
333 es7000_spin(MIP_SPIN
);
336 memcpy(host_reg
, mip_reg
, sizeof(struct mip_reg
));
341 while (((unsigned long long)mip_reg
->off_38
&
342 (unsigned long long)MIP_VALID
) == 0) {
344 printk("es7000_mip_write: Timeout waiting for MIP Valid Flag");
347 es7000_spin(MIP_SPIN
);
350 status
= ((unsigned long long)mip_reg
->off_0
&
351 (unsigned long long)0xffff0000000000ULL
) >> 48;
352 mip_reg
->off_38
= ((unsigned long long)mip_reg
->off_38
&
353 (unsigned long long)~MIP_VALID
);
357 void __init
es7000_enable_apic_mode(void)
359 struct mip_reg es7000_mip_reg
;
365 printk("ES7000: Enabling APIC mode.\n");
366 memset(&es7000_mip_reg
, 0, sizeof(struct mip_reg
));
367 es7000_mip_reg
.off_0
= MIP_SW_APIC
;
368 es7000_mip_reg
.off_38
= MIP_VALID
;
370 while ((mip_status
= es7000_mip_write(&es7000_mip_reg
)) != 0) {
371 printk("es7000_enable_apic_mode: command failed, status = %x\n",
377 * APIC driver for the Unisys ES7000 chipset.
379 #define APIC_DEFINITION 1
380 #include <linux/threads.h>
381 #include <linux/cpumask.h>
382 #include <asm/mpspec.h>
383 #include <asm/genapic.h>
384 #include <asm/fixmap.h>
385 #include <asm/apicdef.h>
386 #include <linux/kernel.h>
387 #include <linux/string.h>
388 #include <linux/init.h>
389 #include <linux/acpi.h>
390 #include <linux/smp.h>
393 #define APIC_DFR_VALUE_CLUSTER (APIC_DFR_CLUSTER)
394 #define INT_DELIVERY_MODE_CLUSTER (dest_LowestPrio)
395 #define INT_DEST_MODE_CLUSTER (1) /* logical delivery broadcast to all procs */
397 #define APIC_DFR_VALUE (APIC_DFR_FLAT)
399 extern void es7000_enable_apic_mode(void);
400 extern int apic_version
[MAX_APICS
];
401 extern u8 cpu_2_logical_apicid
[];
402 extern unsigned int boot_cpu_physical_apicid
;
404 extern int parse_unisys_oem (char *oemptr
);
405 extern int find_unisys_acpi_oem_table(unsigned long *oem_addr
);
406 extern void unmap_unisys_acpi_oem_table(unsigned long oem_addr
);
407 extern void setup_unisys(void);
409 #define apicid_cluster(apicid) (apicid & 0xF0)
410 #define xapic_phys_to_log_apicid(cpu) per_cpu(x86_bios_cpu_apicid, cpu)
412 static void es7000_vector_allocation_domain(int cpu
, cpumask_t
*retmask
)
414 /* Careful. Some cpus do not strictly honor the set of cpus
415 * specified in the interrupt destination when using lowest
416 * priority interrupt delivery mode.
418 * In particular there was a hyperthreading cpu observed to
419 * deliver interrupts to the wrong hyperthread when only one
420 * hyperthread was specified in the interrupt desitination.
422 *retmask
= (cpumask_t
){ { [0] = APIC_ALL_CPUS
, } };
426 static void es7000_wait_for_init_deassert(atomic_t
*deassert
)
428 #ifndef CONFIG_ES7000_CLUSTERED_APIC
429 while (!atomic_read(deassert
))
435 static unsigned int es7000_get_apic_id(unsigned long x
)
437 return (x
>> 24) & 0xFF;
441 static int es7000_check_dsdt(void)
443 struct acpi_table_header header
;
445 if (ACPI_SUCCESS(acpi_get_table_header(ACPI_SIG_DSDT
, 0, &header
)) &&
446 !strncmp(header
.oem_id
, "UNISYS", 6))
452 static void es7000_send_IPI_mask(const struct cpumask
*mask
, int vector
)
454 default_send_IPI_mask_sequence_phys(mask
, vector
);
457 static void es7000_send_IPI_allbutself(int vector
)
459 default_send_IPI_mask_allbutself_phys(cpu_online_mask
, vector
);
462 static void es7000_send_IPI_all(int vector
)
464 es7000_send_IPI_mask(cpu_online_mask
, vector
);
467 static int es7000_apic_id_registered(void)
472 static const cpumask_t
*target_cpus_cluster(void)
474 return &CPU_MASK_ALL
;
477 static const cpumask_t
*es7000_target_cpus(void)
479 return &cpumask_of_cpu(smp_processor_id());
483 es7000_check_apicid_used(physid_mask_t bitmap
, int apicid
)
487 static unsigned long es7000_check_apicid_present(int bit
)
489 return physid_isset(bit
, phys_cpu_present_map
);
492 static unsigned long calculate_ldr(int cpu
)
494 unsigned long id
= xapic_phys_to_log_apicid(cpu
);
496 return (SET_APIC_LOGICAL_ID(id
));
500 * Set up the logical destination ID.
502 * Intel recommends to set DFR, LdR and TPR before enabling
503 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
504 * document number 292116). So here it goes...
506 static void es7000_init_apic_ldr_cluster(void)
509 int cpu
= smp_processor_id();
511 apic_write(APIC_DFR
, APIC_DFR_VALUE_CLUSTER
);
512 val
= calculate_ldr(cpu
);
513 apic_write(APIC_LDR
, val
);
516 static void es7000_init_apic_ldr(void)
519 int cpu
= smp_processor_id();
521 apic_write(APIC_DFR
, APIC_DFR_VALUE
);
522 val
= calculate_ldr(cpu
);
523 apic_write(APIC_LDR
, val
);
526 static void es7000_setup_apic_routing(void)
528 int apic
= per_cpu(x86_bios_cpu_apicid
, smp_processor_id());
529 printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
530 (apic_version
[apic
] == 0x14) ?
531 "Physical Cluster" : "Logical Cluster",
532 nr_ioapics
, cpus_addr(*es7000_target_cpus())[0]);
535 static int es7000_apicid_to_node(int logical_apicid
)
541 static int es7000_cpu_present_to_apicid(int mps_cpu
)
544 return boot_cpu_physical_apicid
;
545 else if (mps_cpu
< nr_cpu_ids
)
546 return (int) per_cpu(x86_bios_cpu_apicid
, mps_cpu
);
551 static physid_mask_t
es7000_apicid_to_cpu_present(int phys_apicid
)
556 mask
= physid_mask_of_physid(id
);
562 /* Mapping from cpu number to logical apicid */
563 static int es7000_cpu_to_logical_apicid(int cpu
)
566 if (cpu
>= nr_cpu_ids
)
568 return (int)cpu_2_logical_apicid
[cpu
];
570 return logical_smp_processor_id();
574 static physid_mask_t
es7000_ioapic_phys_id_map(physid_mask_t phys_map
)
576 /* For clustered we don't have a good way to do this yet - hack */
577 return physids_promote(0xff);
580 static int es7000_check_phys_apicid_present(int cpu_physical_apicid
)
582 boot_cpu_physical_apicid
= read_apic_id();
587 es7000_cpu_mask_to_apicid_cluster(const struct cpumask
*cpumask
)
594 num_bits_set
= cpumask_weight(cpumask
);
595 /* Return id to all */
596 if (num_bits_set
== nr_cpu_ids
)
599 * The cpus in the mask must all be on the apic cluster. If are not
600 * on the same apicid cluster return default value of target_cpus():
602 cpu
= cpumask_first(cpumask
);
603 apicid
= es7000_cpu_to_logical_apicid(cpu
);
605 while (cpus_found
< num_bits_set
) {
606 if (cpumask_test_cpu(cpu
, cpumask
)) {
607 int new_apicid
= es7000_cpu_to_logical_apicid(cpu
);
609 if (apicid_cluster(apicid
) !=
610 apicid_cluster(new_apicid
)) {
611 printk ("%s: Not a valid mask!\n", __func__
);
623 static unsigned int es7000_cpu_mask_to_apicid(const cpumask_t
*cpumask
)
630 num_bits_set
= cpus_weight(*cpumask
);
631 /* Return id to all */
632 if (num_bits_set
== nr_cpu_ids
)
633 return es7000_cpu_to_logical_apicid(0);
635 * The cpus in the mask must all be on the apic cluster. If are not
636 * on the same apicid cluster return default value of target_cpus():
638 cpu
= first_cpu(*cpumask
);
639 apicid
= es7000_cpu_to_logical_apicid(cpu
);
640 while (cpus_found
< num_bits_set
) {
641 if (cpu_isset(cpu
, *cpumask
)) {
642 int new_apicid
= es7000_cpu_to_logical_apicid(cpu
);
644 if (apicid_cluster(apicid
) !=
645 apicid_cluster(new_apicid
)) {
646 printk ("%s: Not a valid mask!\n", __func__
);
648 return es7000_cpu_to_logical_apicid(0);
659 es7000_cpu_mask_to_apicid_and(const struct cpumask
*inmask
,
660 const struct cpumask
*andmask
)
662 int apicid
= es7000_cpu_to_logical_apicid(0);
663 cpumask_var_t cpumask
;
665 if (!alloc_cpumask_var(&cpumask
, GFP_ATOMIC
))
668 cpumask_and(cpumask
, inmask
, andmask
);
669 cpumask_and(cpumask
, cpumask
, cpu_online_mask
);
670 apicid
= es7000_cpu_mask_to_apicid(cpumask
);
672 free_cpumask_var(cpumask
);
677 static int es7000_phys_pkg_id(int cpuid_apic
, int index_msb
)
679 return cpuid_apic
>> index_msb
;
682 void __init
es7000_update_genapic_to_cluster(void)
684 apic
->target_cpus
= target_cpus_cluster
;
685 apic
->irq_delivery_mode
= INT_DELIVERY_MODE_CLUSTER
;
686 apic
->irq_dest_mode
= INT_DEST_MODE_CLUSTER
;
688 apic
->init_apic_ldr
= es7000_init_apic_ldr_cluster
;
690 apic
->cpu_mask_to_apicid
= es7000_cpu_mask_to_apicid_cluster
;
693 static int probe_es7000(void)
695 /* probed later in mptable/ACPI hooks */
700 es7000_mps_oem_check(struct mpc_table
*mpc
, char *oem
, char *productid
)
703 struct mpc_oemtable
*oem_table
=
704 (struct mpc_oemtable
*)mpc
->oemptr
;
706 if (!strncmp(oem
, "UNISYS", 6))
707 return parse_unisys_oem((char *)oem_table
);
713 /* Hook from generic ACPI tables.c */
714 static int __init
es7000_acpi_madt_oem_check(char *oem_id
, char *oem_table_id
)
716 unsigned long oem_addr
= 0;
720 /* check dsdt at first to avoid clear fix_map for oem_addr */
721 check_dsdt
= es7000_check_dsdt();
723 if (!find_unisys_acpi_oem_table(&oem_addr
)) {
725 ret
= parse_unisys_oem((char *)oem_addr
);
731 * we need to unmap it
733 unmap_unisys_acpi_oem_table(oem_addr
);
738 static int __init
es7000_acpi_madt_oem_check(char *oem_id
, char *oem_table_id
)
745 struct genapic apic_es7000
= {
748 .probe
= probe_es7000
,
749 .acpi_madt_oem_check
= es7000_acpi_madt_oem_check
,
750 .apic_id_registered
= es7000_apic_id_registered
,
752 .irq_delivery_mode
= dest_Fixed
,
753 /* phys delivery to target CPUs: */
756 .target_cpus
= es7000_target_cpus
,
759 .check_apicid_used
= es7000_check_apicid_used
,
760 .check_apicid_present
= es7000_check_apicid_present
,
762 .vector_allocation_domain
= es7000_vector_allocation_domain
,
763 .init_apic_ldr
= es7000_init_apic_ldr
,
765 .ioapic_phys_id_map
= es7000_ioapic_phys_id_map
,
766 .setup_apic_routing
= es7000_setup_apic_routing
,
767 .multi_timer_check
= NULL
,
768 .apicid_to_node
= es7000_apicid_to_node
,
769 .cpu_to_logical_apicid
= es7000_cpu_to_logical_apicid
,
770 .cpu_present_to_apicid
= es7000_cpu_present_to_apicid
,
771 .apicid_to_cpu_present
= es7000_apicid_to_cpu_present
,
772 .setup_portio_remap
= NULL
,
773 .check_phys_apicid_present
= es7000_check_phys_apicid_present
,
774 .enable_apic_mode
= es7000_enable_apic_mode
,
775 .phys_pkg_id
= es7000_phys_pkg_id
,
776 .mps_oem_check
= es7000_mps_oem_check
,
778 .get_apic_id
= es7000_get_apic_id
,
780 .apic_id_mask
= 0xFF << 24,
782 .cpu_mask_to_apicid
= es7000_cpu_mask_to_apicid
,
783 .cpu_mask_to_apicid_and
= es7000_cpu_mask_to_apicid_and
,
785 .send_IPI_mask
= es7000_send_IPI_mask
,
786 .send_IPI_mask_allbutself
= NULL
,
787 .send_IPI_allbutself
= es7000_send_IPI_allbutself
,
788 .send_IPI_all
= es7000_send_IPI_all
,
789 .send_IPI_self
= default_send_IPI_self
,
793 .trampoline_phys_low
= 0x467,
794 .trampoline_phys_high
= 0x469,
796 .wait_for_init_deassert
= es7000_wait_for_init_deassert
,
798 /* Nothing to do for most platforms, since cleared by the INIT cycle: */
799 .smp_callin_clear_local_apic
= NULL
,
800 .store_NMI_vector
= NULL
,
801 .inquire_remote_apic
= default_inquire_remote_apic
,