1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include <linux/mm.h>
30#include <linux/init.h>
31#include <asm/io.h>
32#include <asm/bios_ebda.h>
33
34
35
36
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>
42#include <asm/fixmap.h>
43#include <asm/apicdef.h>
44#include <asm/ipi.h>
45#include <linux/kernel.h>
46#include <linux/string.h>
47#include <linux/gfp.h>
48#include <linux/smp.h>
49
50static unsigned summit_get_apic_id(unsigned long x)
51{
52 return (x >> 24) & 0xFF;
53}
54
55static inline void summit_send_IPI_mask(const struct cpumask *mask, int vector)
56{
57 default_send_IPI_mask_sequence_logical(mask, vector);
58}
59
60static void summit_send_IPI_allbutself(int vector)
61{
62 default_send_IPI_mask_allbutself_logical(cpu_online_mask, vector);
63}
64
65static void summit_send_IPI_all(int vector)
66{
67 summit_send_IPI_mask(cpu_online_mask, vector);
68}
69
70#include <asm/tsc.h>
71
72extern int use_cyclone;
73
74#ifdef CONFIG_X86_SUMMIT_NUMA
75static void setup_summit(void);
76#else
77static inline void setup_summit(void) {}
78#endif
79
80static int summit_mps_oem_check(struct mpc_table *mpc, char *oem,
81 char *productid)
82{
83 if (!strncmp(oem, "IBM ENSW", 8) &&
84 (!strncmp(productid, "VIGIL SMP", 9)
85 || !strncmp(productid, "EXA", 3)
86 || !strncmp(productid, "RUTHLESS SMP", 12))){
87 mark_tsc_unstable("Summit based system");
88 use_cyclone = 1;
89 setup_summit();
90 return 1;
91 }
92 return 0;
93}
94
95
96static int summit_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
97{
98 if (!strncmp(oem_id, "IBM", 3) &&
99 (!strncmp(oem_table_id, "SERVIGIL", 8)
100 || !strncmp(oem_table_id, "EXA", 3))){
101 mark_tsc_unstable("Summit based system");
102 use_cyclone = 1;
103 setup_summit();
104 return 1;
105 }
106 return 0;
107}
108
109struct rio_table_hdr {
110 unsigned char version;
111
112 unsigned char num_scal_dev;
113 unsigned char num_rio_dev;
114} __attribute__((packed));
115
116struct scal_detail {
117 unsigned char node_id;
118 unsigned long CBAR;
119 unsigned char port0node;
120 unsigned char port0port;
121 unsigned char port1node;
122 unsigned char port1port;
123 unsigned char port2node;
124 unsigned char port2port;
125 unsigned char chassis_num;
126} __attribute__((packed));
127
128struct rio_detail {
129 unsigned char node_id;
130 unsigned long BBAR;
131 unsigned char type;
132 unsigned char owner_id;
133
134 unsigned char port0node;
135 unsigned char port0port;
136 unsigned char port1node;
137 unsigned char port1port;
138 unsigned char first_slot;
139
140 unsigned char status;
141
142
143
144
145 unsigned char WP_index;
146
147
148 unsigned char chassis_num;
149
150
151
152
153
154
155
156} __attribute__((packed));
157
158
159typedef enum {
160 CompatTwister = 0,
161 AltTwister = 1,
162 CompatCyclone = 2,
163 AltCyclone = 3,
164 CompatWPEG = 4,
165 AltWPEG = 5,
166 LookOutAWPEG = 6,
167 LookOutBWPEG = 7,
168} node_type;
169
170static inline int is_WPEG(struct rio_detail *rio){
171 return (rio->type == CompatWPEG || rio->type == AltWPEG ||
172 rio->type == LookOutAWPEG || rio->type == LookOutBWPEG);
173}
174
175#define SUMMIT_APIC_DFR_VALUE (APIC_DFR_CLUSTER)
176
177static const struct cpumask *summit_target_cpus(void)
178{
179
180
181
182
183 return cpumask_of(0);
184}
185
186static unsigned long summit_check_apicid_used(physid_mask_t *map, int apicid)
187{
188 return 0;
189}
190
191
192static unsigned long summit_check_apicid_present(int bit)
193{
194 return 1;
195}
196
197static int summit_early_logical_apicid(int cpu)
198{
199 int count = 0;
200 u8 my_id = early_per_cpu(x86_cpu_to_apicid, cpu);
201 u8 my_cluster = APIC_CLUSTER(my_id);
202#ifdef CONFIG_SMP
203 u8 lid;
204 int i;
205
206
207 for (count = 0, i = nr_cpu_ids; --i >= 0; ) {
208 lid = early_per_cpu(x86_cpu_to_logical_apicid, i);
209 if (lid != BAD_APICID && APIC_CLUSTER(lid) == my_cluster)
210 ++count;
211 }
212#endif
213
214
215 BUG_ON(count >= XAPIC_DEST_CPUS_SHIFT);
216 return my_cluster | (1UL << count);
217}
218
219static void summit_init_apic_ldr(void)
220{
221 int cpu = smp_processor_id();
222 unsigned long id = early_per_cpu(x86_cpu_to_logical_apicid, cpu);
223 unsigned long val;
224
225 apic_write(APIC_DFR, SUMMIT_APIC_DFR_VALUE);
226 val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
227 val |= SET_APIC_LOGICAL_ID(id);
228 apic_write(APIC_LDR, val);
229}
230
231static int summit_apic_id_registered(void)
232{
233 return 1;
234}
235
236static void summit_setup_apic_routing(void)
237{
238 printk("Enabling APIC mode: Summit. Using %d I/O APICs\n",
239 nr_ioapics);
240}
241
242static int summit_cpu_present_to_apicid(int mps_cpu)
243{
244 if (mps_cpu < nr_cpu_ids)
245 return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);
246 else
247 return BAD_APICID;
248}
249
250static void summit_ioapic_phys_id_map(physid_mask_t *phys_id_map, physid_mask_t *retmap)
251{
252
253 physids_promote(0x0FL, retmap);
254}
255
256static void summit_apicid_to_cpu_present(int apicid, physid_mask_t *retmap)
257{
258 physid_set_mask_of_physid(0, retmap);
259}
260
261static int summit_check_phys_apicid_present(int physical_apicid)
262{
263 return 1;
264}
265
266static unsigned int summit_cpu_mask_to_apicid(const struct cpumask *cpumask)
267{
268 unsigned int round = 0;
269 int cpu, apicid = 0;
270
271
272
273
274 for_each_cpu(cpu, cpumask) {
275 int new_apicid = early_per_cpu(x86_cpu_to_logical_apicid, cpu);
276
277 if (round && APIC_CLUSTER(apicid) != APIC_CLUSTER(new_apicid)) {
278 printk("%s: Not a valid mask!\n", __func__);
279 return BAD_APICID;
280 }
281 apicid |= new_apicid;
282 round++;
283 }
284 return apicid;
285}
286
287static unsigned int summit_cpu_mask_to_apicid_and(const struct cpumask *inmask,
288 const struct cpumask *andmask)
289{
290 int apicid = early_per_cpu(x86_cpu_to_logical_apicid, 0);
291 cpumask_var_t cpumask;
292
293 if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC))
294 return apicid;
295
296 cpumask_and(cpumask, inmask, andmask);
297 cpumask_and(cpumask, cpumask, cpu_online_mask);
298 apicid = summit_cpu_mask_to_apicid(cpumask);
299
300 free_cpumask_var(cpumask);
301
302 return apicid;
303}
304
305
306
307
308
309
310
311
312static int summit_phys_pkg_id(int cpuid_apic, int index_msb)
313{
314 return hard_smp_processor_id() >> index_msb;
315}
316
317static int probe_summit(void)
318{
319
320 return 0;
321}
322
323static void summit_vector_allocation_domain(int cpu, struct cpumask *retmask)
324{
325
326
327
328
329
330
331
332
333 cpumask_clear(retmask);
334 cpumask_bits(retmask)[0] = APIC_ALL_CPUS;
335}
336
337#ifdef CONFIG_X86_SUMMIT_NUMA
338static struct rio_table_hdr *rio_table_hdr;
339static struct scal_detail *scal_devs[MAX_NUMNODES];
340static struct rio_detail *rio_devs[MAX_NUMNODES*4];
341
342#ifndef CONFIG_X86_NUMAQ
343static int mp_bus_id_to_node[MAX_MP_BUSSES];
344#endif
345
346static int setup_pci_node_map_for_wpeg(int wpeg_num, int last_bus)
347{
348 int twister = 0, node = 0;
349 int i, bus, num_buses;
350
351 for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {
352 if (rio_devs[i]->node_id == rio_devs[wpeg_num]->owner_id) {
353 twister = rio_devs[i]->owner_id;
354 break;
355 }
356 }
357 if (i == rio_table_hdr->num_rio_dev) {
358 printk(KERN_ERR "%s: Couldn't find owner Cyclone for Winnipeg!\n", __func__);
359 return last_bus;
360 }
361
362 for (i = 0; i < rio_table_hdr->num_scal_dev; i++) {
363 if (scal_devs[i]->node_id == twister) {
364 node = scal_devs[i]->node_id;
365 break;
366 }
367 }
368 if (i == rio_table_hdr->num_scal_dev) {
369 printk(KERN_ERR "%s: Couldn't find owner Twister for Cyclone!\n", __func__);
370 return last_bus;
371 }
372
373 switch (rio_devs[wpeg_num]->type) {
374 case CompatWPEG:
375
376
377
378
379
380 num_buses = 5;
381 break;
382 case AltWPEG:
383
384
385
386
387
388 num_buses = 7;
389 break;
390 case LookOutAWPEG:
391 case LookOutBWPEG:
392
393
394
395
396 num_buses = 9;
397 break;
398 default:
399 printk(KERN_INFO "%s: Unsupported Winnipeg type!\n", __func__);
400 return last_bus;
401 }
402
403 for (bus = last_bus; bus < last_bus + num_buses; bus++)
404 mp_bus_id_to_node[bus] = node;
405 return bus;
406}
407
408static int build_detail_arrays(void)
409{
410 unsigned long ptr;
411 int i, scal_detail_size, rio_detail_size;
412
413 if (rio_table_hdr->num_scal_dev > MAX_NUMNODES) {
414 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);
415 return 0;
416 }
417
418 switch (rio_table_hdr->version) {
419 default:
420 printk(KERN_WARNING "%s: Invalid Rio Grande Table Version: %d\n", __func__, rio_table_hdr->version);
421 return 0;
422 case 2:
423 scal_detail_size = 11;
424 rio_detail_size = 13;
425 break;
426 case 3:
427 scal_detail_size = 12;
428 rio_detail_size = 15;
429 break;
430 }
431
432 ptr = (unsigned long)rio_table_hdr + 3;
433 for (i = 0; i < rio_table_hdr->num_scal_dev; i++, ptr += scal_detail_size)
434 scal_devs[i] = (struct scal_detail *)ptr;
435
436 for (i = 0; i < rio_table_hdr->num_rio_dev; i++, ptr += rio_detail_size)
437 rio_devs[i] = (struct rio_detail *)ptr;
438
439 return 1;
440}
441
442void setup_summit(void)
443{
444 unsigned long ptr;
445 unsigned short offset;
446 int i, next_wpeg, next_bus = 0;
447
448
449 ptr = get_bios_ebda();
450 ptr = (unsigned long)phys_to_virt(ptr);
451
452 rio_table_hdr = NULL;
453 offset = 0x180;
454 while (offset) {
455
456 if (*((unsigned short *)(ptr + offset + 2)) == 0x4752) {
457
458 rio_table_hdr = (struct rio_table_hdr *)(ptr + offset + 4);
459 break;
460 }
461
462 offset = *((unsigned short *)(ptr + offset));
463 }
464 if (!rio_table_hdr) {
465 printk(KERN_ERR "%s: Unable to locate Rio Grande Table in EBDA - bailing!\n", __func__);
466 return;
467 }
468
469 if (!build_detail_arrays())
470 return;
471
472
473 next_wpeg = 0;
474 do {
475 for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {
476 if (is_WPEG(rio_devs[i]) && rio_devs[i]->WP_index == next_wpeg) {
477
478 next_bus = setup_pci_node_map_for_wpeg(i, next_bus);
479 next_wpeg++;
480 break;
481 }
482 }
483
484
485
486
487
488 if (i == rio_table_hdr->num_rio_dev)
489 next_wpeg = 0;
490 } while (next_wpeg != 0);
491}
492#endif
493
494static struct apic apic_summit = {
495
496 .name = "summit",
497 .probe = probe_summit,
498 .acpi_madt_oem_check = summit_acpi_madt_oem_check,
499 .apic_id_registered = summit_apic_id_registered,
500
501 .irq_delivery_mode = dest_LowestPrio,
502
503 .irq_dest_mode = 1,
504
505 .target_cpus = summit_target_cpus,
506 .disable_esr = 1,
507 .dest_logical = APIC_DEST_LOGICAL,
508 .check_apicid_used = summit_check_apicid_used,
509 .check_apicid_present = summit_check_apicid_present,
510
511 .vector_allocation_domain = summit_vector_allocation_domain,
512 .init_apic_ldr = summit_init_apic_ldr,
513
514 .ioapic_phys_id_map = summit_ioapic_phys_id_map,
515 .setup_apic_routing = summit_setup_apic_routing,
516 .multi_timer_check = NULL,
517 .cpu_present_to_apicid = summit_cpu_present_to_apicid,
518 .apicid_to_cpu_present = summit_apicid_to_cpu_present,
519 .setup_portio_remap = NULL,
520 .check_phys_apicid_present = summit_check_phys_apicid_present,
521 .enable_apic_mode = NULL,
522 .phys_pkg_id = summit_phys_pkg_id,
523 .mps_oem_check = summit_mps_oem_check,
524
525 .get_apic_id = summit_get_apic_id,
526 .set_apic_id = NULL,
527 .apic_id_mask = 0xFF << 24,
528
529 .cpu_mask_to_apicid = summit_cpu_mask_to_apicid,
530 .cpu_mask_to_apicid_and = summit_cpu_mask_to_apicid_and,
531
532 .send_IPI_mask = summit_send_IPI_mask,
533 .send_IPI_mask_allbutself = NULL,
534 .send_IPI_allbutself = summit_send_IPI_allbutself,
535 .send_IPI_all = summit_send_IPI_all,
536 .send_IPI_self = default_send_IPI_self,
537
538 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
539 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
540
541 .wait_for_init_deassert = default_wait_for_init_deassert,
542
543 .smp_callin_clear_local_apic = NULL,
544 .inquire_remote_apic = default_inquire_remote_apic,
545
546 .read = native_apic_mem_read,
547 .write = native_apic_mem_write,
548 .icr_read = native_apic_icr_read,
549 .icr_write = native_apic_icr_write,
550 .wait_icr_idle = native_apic_wait_icr_idle,
551 .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
552
553 .x86_32_early_logical_apicid = summit_early_logical_apicid,
554};
555
556apic_driver(apic_summit);
557