x86_32: summit_32, use BAD_APICID
[deliverable/linux.git] / arch / x86 / kernel / apic / summit_32.c
CommitLineData
1da177e4 1/*
835c34a1 2 * IBM Summit-Specific Code
1da177e4
LT
3 *
4 * Written By: Matthew Dobson, IBM Corporation
5 *
6 * Copyright (c) 2003 IBM Corp.
7 *
8 * All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18 * NON INFRINGEMENT. See the GNU General Public License for more
19 * details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * Send feedback to <colpatch@us.ibm.com>
26 *
27 */
28
29#include <linux/mm.h>
30#include <linux/init.h>
31#include <asm/io.h>
356fa0c6 32#include <asm/bios_ebda.h>
b11b867f
IM
33
34/*
35 * APIC driver for the IBM "Summit" chipset.
36 */
b11b867f
IM
37#include <linux/threads.h>
38#include <linux/cpumask.h>
39#include <asm/mpspec.h>
40#include <asm/apic.h>
41#include <asm/smp.h>
b11b867f
IM
42#include <asm/fixmap.h>
43#include <asm/apicdef.h>
43f39890 44#include <asm/ipi.h>
b11b867f
IM
45#include <linux/kernel.h>
46#include <linux/string.h>
47#include <linux/init.h>
48#include <linux/gfp.h>
49#include <linux/smp.h>
50
51static inline unsigned summit_get_apic_id(unsigned long x)
52{
53 return (x >> 24) & 0xFF;
54}
55
b11b867f
IM
56static inline void summit_send_IPI_mask(const cpumask_t *mask, int vector)
57{
43f39890 58 default_send_IPI_mask_sequence_logical(mask, vector);
b11b867f
IM
59}
60
61static inline void summit_send_IPI_allbutself(int vector)
62{
63 cpumask_t mask = cpu_online_map;
64 cpu_clear(smp_processor_id(), mask);
65
66 if (!cpus_empty(mask))
67 summit_send_IPI_mask(&mask, vector);
68}
69
70static inline void summit_send_IPI_all(int vector)
71{
72 summit_send_IPI_mask(&cpu_online_map, vector);
73}
74
75#include <asm/tsc.h>
76
77extern int use_cyclone;
78
79#ifdef CONFIG_X86_SUMMIT_NUMA
80extern void setup_summit(void);
81#else
82#define setup_summit() {}
83#endif
84
85static inline int
86summit_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid)
87{
88 if (!strncmp(oem, "IBM ENSW", 8) &&
89 (!strncmp(productid, "VIGIL SMP", 9)
90 || !strncmp(productid, "EXA", 3)
91 || !strncmp(productid, "RUTHLESS SMP", 12))){
92 mark_tsc_unstable("Summit based system");
93 use_cyclone = 1; /*enable cyclone-timer*/
94 setup_summit();
95 return 1;
96 }
97 return 0;
98}
99
100/* Hook from generic ACPI tables.c */
101static inline int summit_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
102{
103 if (!strncmp(oem_id, "IBM", 3) &&
104 (!strncmp(oem_table_id, "SERVIGIL", 8)
105 || !strncmp(oem_table_id, "EXA", 3))){
106 mark_tsc_unstable("Summit based system");
107 use_cyclone = 1; /*enable cyclone-timer*/
108 setup_summit();
109 return 1;
110 }
111 return 0;
112}
113
114struct rio_table_hdr {
115 unsigned char version; /* Version number of this data structure */
116 /* Version 3 adds chassis_num & WP_index */
117 unsigned char num_scal_dev; /* # of Scalability devices (Twisters for Vigil) */
118 unsigned char num_rio_dev; /* # of RIO I/O devices (Cyclones and Winnipegs) */
119} __attribute__((packed));
120
121struct scal_detail {
122 unsigned char node_id; /* Scalability Node ID */
123 unsigned long CBAR; /* Address of 1MB register space */
124 unsigned char port0node; /* Node ID port connected to: 0xFF=None */
125 unsigned char port0port; /* Port num port connected to: 0,1,2, or 0xFF=None */
126 unsigned char port1node; /* Node ID port connected to: 0xFF = None */
127 unsigned char port1port; /* Port num port connected to: 0,1,2, or 0xFF=None */
128 unsigned char port2node; /* Node ID port connected to: 0xFF = None */
129 unsigned char port2port; /* Port num port connected to: 0,1,2, or 0xFF=None */
130 unsigned char chassis_num; /* 1 based Chassis number (1 = boot node) */
131} __attribute__((packed));
132
133struct rio_detail {
134 unsigned char node_id; /* RIO Node ID */
135 unsigned long BBAR; /* Address of 1MB register space */
136 unsigned char type; /* Type of device */
137 unsigned char owner_id; /* For WPEG: Node ID of Cyclone that owns this WPEG*/
138 /* For CYC: Node ID of Twister that owns this CYC */
139 unsigned char port0node; /* Node ID port connected to: 0xFF=None */
140 unsigned char port0port; /* Port num port connected to: 0,1,2, or 0xFF=None */
141 unsigned char port1node; /* Node ID port connected to: 0xFF=None */
142 unsigned char port1port; /* Port num port connected to: 0,1,2, or 0xFF=None */
143 unsigned char first_slot; /* For WPEG: Lowest slot number below this WPEG */
144 /* For CYC: 0 */
145 unsigned char status; /* For WPEG: Bit 0 = 1 : the XAPIC is used */
146 /* = 0 : the XAPIC is not used, ie:*/
147 /* ints fwded to another XAPIC */
148 /* Bits1:7 Reserved */
149 /* For CYC: Bits0:7 Reserved */
150 unsigned char WP_index; /* For WPEG: WPEG instance index - lower ones have */
151 /* lower slot numbers/PCI bus numbers */
152 /* For CYC: No meaning */
153 unsigned char chassis_num; /* 1 based Chassis number */
154 /* For LookOut WPEGs this field indicates the */
155 /* Expansion Chassis #, enumerated from Boot */
156 /* Node WPEG external port, then Boot Node CYC */
157 /* external port, then Next Vigil chassis WPEG */
158 /* external port, etc. */
159 /* Shared Lookouts have only 1 chassis number (the */
160 /* first one assigned) */
161} __attribute__((packed));
162
163
164typedef enum {
165 CompatTwister = 0, /* Compatibility Twister */
166 AltTwister = 1, /* Alternate Twister of internal 8-way */
167 CompatCyclone = 2, /* Compatibility Cyclone */
168 AltCyclone = 3, /* Alternate Cyclone of internal 8-way */
169 CompatWPEG = 4, /* Compatibility WPEG */
170 AltWPEG = 5, /* Second Planar WPEG */
171 LookOutAWPEG = 6, /* LookOut WPEG */
172 LookOutBWPEG = 7, /* LookOut WPEG */
173} node_type;
174
175static inline int is_WPEG(struct rio_detail *rio){
176 return (rio->type == CompatWPEG || rio->type == AltWPEG ||
177 rio->type == LookOutAWPEG || rio->type == LookOutBWPEG);
178}
179
180
181/* In clustered mode, the high nibble of APIC ID is a cluster number.
182 * The low nibble is a 4-bit bitmap. */
183#define XAPIC_DEST_CPUS_SHIFT 4
184#define XAPIC_DEST_CPUS_MASK ((1u << XAPIC_DEST_CPUS_SHIFT) - 1)
185#define XAPIC_DEST_CLUSTER_MASK (XAPIC_DEST_CPUS_MASK << XAPIC_DEST_CPUS_SHIFT)
186
187#define SUMMIT_APIC_DFR_VALUE (APIC_DFR_CLUSTER)
188
189static inline const cpumask_t *summit_target_cpus(void)
190{
191 /* CPU_MASK_ALL (0xff) has undefined behaviour with
192 * dest_LowestPrio mode logical clustered apic interrupt routing
193 * Just start on cpu 0. IRQ balancing will spread load
194 */
195 return &cpumask_of_cpu(0);
196}
197
198static inline unsigned long
199summit_check_apicid_used(physid_mask_t bitmap, int apicid)
200{
201 return 0;
202}
203
204/* we don't use the phys_cpu_present_map to indicate apicid presence */
205static inline unsigned long summit_check_apicid_present(int bit)
206{
207 return 1;
208}
209
b11b867f
IM
210static inline void summit_init_apic_ldr(void)
211{
212 unsigned long val, id;
213 int count = 0;
214 u8 my_id = (u8)hard_smp_processor_id();
b9e0d1aa 215 u8 my_cluster = APIC_CLUSTER(my_id);
b11b867f
IM
216#ifdef CONFIG_SMP
217 u8 lid;
218 int i;
219
220 /* Create logical APIC IDs by counting CPUs already in cluster. */
221 for (count = 0, i = nr_cpu_ids; --i >= 0; ) {
222 lid = cpu_2_logical_apicid[i];
b9e0d1aa 223 if (lid != BAD_APICID && APIC_CLUSTER(lid) == my_cluster)
b11b867f
IM
224 ++count;
225 }
226#endif
227 /* We only have a 4 wide bitmap in cluster mode. If a deranged
228 * BIOS puts 5 CPUs in one APIC cluster, we're hosed. */
229 BUG_ON(count >= XAPIC_DEST_CPUS_SHIFT);
230 id = my_cluster | (1UL << count);
231 apic_write(APIC_DFR, SUMMIT_APIC_DFR_VALUE);
232 val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
233 val |= SET_APIC_LOGICAL_ID(id);
234 apic_write(APIC_LDR, val);
235}
236
237static inline int summit_apic_id_registered(void)
238{
239 return 1;
240}
241
242static inline void summit_setup_apic_routing(void)
243{
244 printk("Enabling APIC mode: Summit. Using %d I/O APICs\n",
245 nr_ioapics);
246}
247
248static inline int summit_apicid_to_node(int logical_apicid)
249{
250#ifdef CONFIG_SMP
251 return apicid_2_node[hard_smp_processor_id()];
252#else
253 return 0;
254#endif
255}
256
257/* Mapping from cpu number to logical apicid */
258static inline int summit_cpu_to_logical_apicid(int cpu)
259{
260#ifdef CONFIG_SMP
261 if (cpu >= nr_cpu_ids)
262 return BAD_APICID;
2f205bc4 263 return cpu_2_logical_apicid[cpu];
b11b867f
IM
264#else
265 return logical_smp_processor_id();
266#endif
267}
268
269static inline int summit_cpu_present_to_apicid(int mps_cpu)
270{
271 if (mps_cpu < nr_cpu_ids)
272 return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);
273 else
274 return BAD_APICID;
275}
276
277static inline physid_mask_t
278summit_ioapic_phys_id_map(physid_mask_t phys_id_map)
279{
280 /* For clustered we don't have a good way to do this yet - hack */
281 return physids_promote(0x0F);
282}
283
284static inline physid_mask_t summit_apicid_to_cpu_present(int apicid)
285{
286 return physid_mask_of_physid(0);
287}
288
289static inline void summit_setup_portio_remap(void)
290{
291}
292
293static inline int summit_check_phys_apicid_present(int boot_cpu_physical_apicid)
294{
295 return 1;
296}
297
298static inline unsigned int summit_cpu_mask_to_apicid(const cpumask_t *cpumask)
299{
300 int cpus_found = 0;
301 int num_bits_set;
302 int apicid;
303 int cpu;
304
305 num_bits_set = cpus_weight(*cpumask);
b11b867f 306 if (num_bits_set >= nr_cpu_ids)
10b614ea 307 return BAD_APICID;
b11b867f 308 /*
10b614ea 309 * The cpus in the mask must all be on the apic cluster.
b11b867f
IM
310 */
311 cpu = first_cpu(*cpumask);
312 apicid = summit_cpu_to_logical_apicid(cpu);
313
314 while (cpus_found < num_bits_set) {
315 if (cpu_isset(cpu, *cpumask)) {
316 int new_apicid = summit_cpu_to_logical_apicid(cpu);
317
b9e0d1aa 318 if (APIC_CLUSTER(apicid) != APIC_CLUSTER(new_apicid)) {
10b614ea 319 printk("%s: Not a valid mask!\n", __func__);
b11b867f 320
10b614ea 321 return BAD_APICID;
b11b867f
IM
322 }
323 apicid = apicid | new_apicid;
324 cpus_found++;
325 }
326 cpu++;
327 }
328 return apicid;
329}
330
331static inline unsigned int
332summit_cpu_mask_to_apicid_and(const struct cpumask *inmask,
333 const struct cpumask *andmask)
334{
335 int apicid = summit_cpu_to_logical_apicid(0);
336 cpumask_var_t cpumask;
337
338 if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC))
339 return apicid;
340
341 cpumask_and(cpumask, inmask, andmask);
342 cpumask_and(cpumask, cpumask, cpu_online_mask);
343 apicid = summit_cpu_mask_to_apicid(cpumask);
344
345 free_cpumask_var(cpumask);
346
347 return apicid;
348}
349
350/*
351 * cpuid returns the value latched in the HW at reset, not the APIC ID
352 * register's value. For any box whose BIOS changes APIC IDs, like
353 * clustered APIC systems, we must use hard_smp_processor_id.
354 *
355 * See Intel's IA-32 SW Dev's Manual Vol2 under CPUID.
356 */
357static inline int summit_phys_pkg_id(int cpuid_apic, int index_msb)
358{
359 return hard_smp_processor_id() >> index_msb;
360}
361
362static int probe_summit(void)
363{
364 /* probed later in mptable/ACPI hooks */
365 return 0;
366}
367
368static void summit_vector_allocation_domain(int cpu, cpumask_t *retmask)
369{
370 /* Careful. Some cpus do not strictly honor the set of cpus
371 * specified in the interrupt destination when using lowest
372 * priority interrupt delivery mode.
373 *
374 * In particular there was a hyperthreading cpu observed to
375 * deliver interrupts to the wrong hyperthread when only one
376 * hyperthread was specified in the interrupt desitination.
377 */
378 *retmask = (cpumask_t){ { [0] = APIC_ALL_CPUS, } };
379}
1da177e4 380
7c20dcc5 381#ifdef CONFIG_X86_SUMMIT_NUMA
1da177e4
LT
382static struct rio_table_hdr *rio_table_hdr __initdata;
383static struct scal_detail *scal_devs[MAX_NUMNODES] __initdata;
384static struct rio_detail *rio_devs[MAX_NUMNODES*4] __initdata;
385
d49c4288 386#ifndef CONFIG_X86_NUMAQ
037cab07 387static int mp_bus_id_to_node[MAX_MP_BUSSES] __initdata;
d49c4288 388#endif
037cab07 389
1da177e4
LT
390static int __init setup_pci_node_map_for_wpeg(int wpeg_num, int last_bus)
391{
392 int twister = 0, node = 0;
393 int i, bus, num_buses;
394
60e11746
PC
395 for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {
396 if (rio_devs[i]->node_id == rio_devs[wpeg_num]->owner_id) {
1da177e4
LT
397 twister = rio_devs[i]->owner_id;
398 break;
399 }
400 }
60e11746 401 if (i == rio_table_hdr->num_rio_dev) {
77bf90ed 402 printk(KERN_ERR "%s: Couldn't find owner Cyclone for Winnipeg!\n", __func__);
1da177e4
LT
403 return last_bus;
404 }
405
60e11746
PC
406 for (i = 0; i < rio_table_hdr->num_scal_dev; i++) {
407 if (scal_devs[i]->node_id == twister) {
1da177e4
LT
408 node = scal_devs[i]->node_id;
409 break;
410 }
411 }
60e11746 412 if (i == rio_table_hdr->num_scal_dev) {
77bf90ed 413 printk(KERN_ERR "%s: Couldn't find owner Twister for Cyclone!\n", __func__);
1da177e4
LT
414 return last_bus;
415 }
416
60e11746 417 switch (rio_devs[wpeg_num]->type) {
1da177e4 418 case CompatWPEG:
60e11746
PC
419 /*
420 * The Compatibility Winnipeg controls the 2 legacy buses,
1da177e4
LT
421 * the 66MHz PCI bus [2 slots] and the 2 "extra" buses in case
422 * a PCI-PCI bridge card is used in either slot: total 5 buses.
423 */
424 num_buses = 5;
425 break;
426 case AltWPEG:
60e11746
PC
427 /*
428 * The Alternate Winnipeg controls the 2 133MHz buses [1 slot
1da177e4
LT
429 * each], their 2 "extra" buses, the 100MHz bus [2 slots] and
430 * the "extra" buses for each of those slots: total 7 buses.
431 */
432 num_buses = 7;
433 break;
434 case LookOutAWPEG:
435 case LookOutBWPEG:
60e11746
PC
436 /*
437 * A Lookout Winnipeg controls 3 100MHz buses [2 slots each]
1da177e4
LT
438 * & the "extra" buses for each of those slots: total 9 buses.
439 */
440 num_buses = 9;
441 break;
442 default:
77bf90ed 443 printk(KERN_INFO "%s: Unsupported Winnipeg type!\n", __func__);
1da177e4
LT
444 return last_bus;
445 }
446
60e11746 447 for (bus = last_bus; bus < last_bus + num_buses; bus++)
1da177e4
LT
448 mp_bus_id_to_node[bus] = node;
449 return bus;
450}
451
452static int __init build_detail_arrays(void)
453{
454 unsigned long ptr;
455 int i, scal_detail_size, rio_detail_size;
456
60e11746 457 if (rio_table_hdr->num_scal_dev > MAX_NUMNODES) {
77bf90ed 458 printk(KERN_WARNING "%s: MAX_NUMNODES too low! Defined as %d, but system has %d nodes.\n", __func__, MAX_NUMNODES, rio_table_hdr->num_scal_dev);
1da177e4
LT
459 return 0;
460 }
461
60e11746 462 switch (rio_table_hdr->version) {
1da177e4 463 default:
77bf90ed 464 printk(KERN_WARNING "%s: Invalid Rio Grande Table Version: %d\n", __func__, rio_table_hdr->version);
1da177e4
LT
465 return 0;
466 case 2:
467 scal_detail_size = 11;
468 rio_detail_size = 13;
469 break;
470 case 3:
471 scal_detail_size = 12;
472 rio_detail_size = 15;
473 break;
474 }
475
476 ptr = (unsigned long)rio_table_hdr + 3;
60e11746 477 for (i = 0; i < rio_table_hdr->num_scal_dev; i++, ptr += scal_detail_size)
1da177e4
LT
478 scal_devs[i] = (struct scal_detail *)ptr;
479
60e11746 480 for (i = 0; i < rio_table_hdr->num_rio_dev; i++, ptr += rio_detail_size)
1da177e4
LT
481 rio_devs[i] = (struct rio_detail *)ptr;
482
483 return 1;
484}
485
486void __init setup_summit(void)
487{
488 unsigned long ptr;
489 unsigned short offset;
490 int i, next_wpeg, next_bus = 0;
491
492 /* The pointer to the EBDA is stored in the word @ phys 0x40E(40:0E) */
356fa0c6
AM
493 ptr = get_bios_ebda();
494 ptr = (unsigned long)phys_to_virt(ptr);
1da177e4
LT
495
496 rio_table_hdr = NULL;
497 offset = 0x180;
60e11746 498 while (offset) {
1da177e4 499 /* The block id is stored in the 2nd word */
60e11746 500 if (*((unsigned short *)(ptr + offset + 2)) == 0x4752) {
1da177e4
LT
501 /* set the pointer past the offset & block id */
502 rio_table_hdr = (struct rio_table_hdr *)(ptr + offset + 4);
503 break;
504 }
505 /* The next offset is stored in the 1st word. 0 means no more */
506 offset = *((unsigned short *)(ptr + offset));
507 }
60e11746 508 if (!rio_table_hdr) {
77bf90ed 509 printk(KERN_ERR "%s: Unable to locate Rio Grande Table in EBDA - bailing!\n", __func__);
1da177e4
LT
510 return;
511 }
512
513 if (!build_detail_arrays())
514 return;
515
516 /* The first Winnipeg we're looking for has an index of 0 */
517 next_wpeg = 0;
518 do {
60e11746
PC
519 for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {
520 if (is_WPEG(rio_devs[i]) && rio_devs[i]->WP_index == next_wpeg) {
1da177e4
LT
521 /* It's the Winnipeg we're looking for! */
522 next_bus = setup_pci_node_map_for_wpeg(i, next_bus);
523 next_wpeg++;
524 break;
525 }
526 }
527 /*
528 * If we go through all Rio devices and don't find one with
529 * the next index, it means we've found all the Winnipegs,
530 * and thus all the PCI buses.
531 */
532 if (i == rio_table_hdr->num_rio_dev)
533 next_wpeg = 0;
534 } while (next_wpeg != 0);
535}
7c20dcc5 536#endif
b11b867f 537
be163a15 538struct apic apic_summit = {
b11b867f
IM
539
540 .name = "summit",
541 .probe = probe_summit,
542 .acpi_madt_oem_check = summit_acpi_madt_oem_check,
543 .apic_id_registered = summit_apic_id_registered,
544
545 .irq_delivery_mode = dest_LowestPrio,
546 /* logical delivery broadcast to all CPUs: */
547 .irq_dest_mode = 1,
548
549 .target_cpus = summit_target_cpus,
550 .disable_esr = 1,
551 .dest_logical = APIC_DEST_LOGICAL,
552 .check_apicid_used = summit_check_apicid_used,
553 .check_apicid_present = summit_check_apicid_present,
554
555 .vector_allocation_domain = summit_vector_allocation_domain,
556 .init_apic_ldr = summit_init_apic_ldr,
557
558 .ioapic_phys_id_map = summit_ioapic_phys_id_map,
559 .setup_apic_routing = summit_setup_apic_routing,
560 .multi_timer_check = NULL,
561 .apicid_to_node = summit_apicid_to_node,
562 .cpu_to_logical_apicid = summit_cpu_to_logical_apicid,
563 .cpu_present_to_apicid = summit_cpu_present_to_apicid,
564 .apicid_to_cpu_present = summit_apicid_to_cpu_present,
565 .setup_portio_remap = NULL,
566 .check_phys_apicid_present = summit_check_phys_apicid_present,
567 .enable_apic_mode = NULL,
568 .phys_pkg_id = summit_phys_pkg_id,
569 .mps_oem_check = summit_mps_oem_check,
570
571 .get_apic_id = summit_get_apic_id,
572 .set_apic_id = NULL,
573 .apic_id_mask = 0xFF << 24,
574
575 .cpu_mask_to_apicid = summit_cpu_mask_to_apicid,
576 .cpu_mask_to_apicid_and = summit_cpu_mask_to_apicid_and,
577
578 .send_IPI_mask = summit_send_IPI_mask,
579 .send_IPI_mask_allbutself = NULL,
580 .send_IPI_allbutself = summit_send_IPI_allbutself,
581 .send_IPI_all = summit_send_IPI_all,
6b64ee02 582 .send_IPI_self = default_send_IPI_self,
b11b867f
IM
583
584 .wakeup_cpu = NULL,
585 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
586 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
587
588 .wait_for_init_deassert = default_wait_for_init_deassert,
589
590 .smp_callin_clear_local_apic = NULL,
b11b867f 591 .inquire_remote_apic = default_inquire_remote_apic,
c1eeb2de
YL
592
593 .read = native_apic_mem_read,
594 .write = native_apic_mem_write,
595 .icr_read = native_apic_icr_read,
596 .icr_write = native_apic_icr_write,
597 .wait_icr_idle = native_apic_wait_icr_idle,
598 .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
b11b867f 599};
This page took 0.44421 seconds and 5 git commands to generate.