1 /*
2  * SMP Support
3  *
4  * Copyright (C) 1999 VA Linux Systems
5  * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
6  * Copyright (C) 2001-2003 Hewlett-Packard Co
7  *	David Mosberger-Tang <davidm@hpl.hp.com>
8  */
9 #ifndef _ASM_IA64_SMP_H
10 #define _ASM_IA64_SMP_H
11 
12 #include <linux/config.h>
13 
14 #ifdef CONFIG_SMP
15 
16 #include <linux/init.h>
17 #include <linux/threads.h>
18 #include <linux/kernel.h>
19 
20 #include <asm/io.h>
21 #include <asm/param.h>
22 #include <asm/processor.h>
23 #include <asm/ptrace.h>
24 
25 #define XTP_OFFSET		0x1e0008
26 
27 #define SMP_IRQ_REDIRECTION	(1 << 0)
28 #define SMP_IPI_REDIRECTION	(1 << 1)
29 
30 #define smp_processor_id()	(current->processor)
31 
32 extern struct smp_boot_data {
33 	int cpu_count;
34 	int cpu_phys_id[NR_CPUS];
35 } smp_boot_data __initdata;
36 
37 extern char no_int_routing __initdata;
38 
39 extern volatile unsigned long cpu_online_map;
40 extern unsigned long ipi_base_addr;
41 extern unsigned char smp_int_redirect;
42 extern int smp_num_cpus;
43 
44 extern volatile int ia64_cpu_to_sapicid[];
45 #define cpu_physical_id(i)	ia64_cpu_to_sapicid[i]
46 #define cpu_number_map(i)	(i)
47 #define cpu_logical_map(i)	(i)
48 
49 extern unsigned long ap_wakeup_vector;
50 
51 #define cpu_online(cpu)		(cpu_online_map & (1UL << (cpu)))
52 
53 /*
54  * Function to map hard smp processor id to logical id.  Slow, so
55  * don't use this in performance-critical code.
56  */
57 static inline int
cpu_logical_id(int cpuid)58 cpu_logical_id (int cpuid)
59 {
60 	int i;
61 
62 	for (i = 0; i < smp_num_cpus; ++i)
63 		if (cpu_physical_id(i) == cpuid)
64 			break;
65 	return i;
66 }
67 
68 /*
69  * XTP control functions:
70  *	min_xtp   : route all interrupts to this CPU
71  *	normal_xtp: nominal XTP value
72  *	max_xtp   : never deliver interrupts to this CPU.
73  */
74 
75 static inline void
min_xtp(void)76 min_xtp (void)
77 {
78 	if (smp_int_redirect & SMP_IRQ_REDIRECTION)
79 		writeb(0x00, ipi_base_addr | XTP_OFFSET); /* XTP to min */
80 }
81 
82 static inline void
normal_xtp(void)83 normal_xtp (void)
84 {
85 	if (smp_int_redirect & SMP_IRQ_REDIRECTION)
86 		writeb(0x08, ipi_base_addr | XTP_OFFSET); /* XTP normal */
87 }
88 
89 static inline void
max_xtp(void)90 max_xtp (void)
91 {
92 	if (smp_int_redirect & SMP_IRQ_REDIRECTION)
93 		writeb(0x0f, ipi_base_addr | XTP_OFFSET); /* Set XTP to max */
94 }
95 
96 static inline unsigned int
hard_smp_processor_id(void)97 hard_smp_processor_id (void)
98 {
99 	union {
100 		struct {
101 			unsigned long reserved : 16;
102 			unsigned long eid : 8;
103 			unsigned long id : 8;
104 			unsigned long ignored : 32;
105 		} f;
106 		unsigned long bits;
107 	} lid;
108 
109 	lid.bits = ia64_get_lid();
110 	return lid.f.id << 8 | lid.f.eid;
111 }
112 
113 #define NO_PROC_ID		0xffffffff	/* no processor magic marker */
114 
115 /*
116  * Extra overhead to move a task from one cpu to another (due to TLB and cache misses).
117  * Expressed in "negative nice value" units (larger number means higher priority/penalty).
118  */
119 #define PROC_CHANGE_PENALTY	20
120 
121 extern void __init init_smp_config (void);
122 extern void smp_do_timer (struct pt_regs *regs);
123 
124 extern int smp_call_function_single (int cpuid, void (*func) (void *info), void *info,
125 				     int retry, int wait);
126 
127 extern void smp_build_cpu_map(void);
128 
129 #endif /* CONFIG_SMP */
130 #endif /* _ASM_IA64_SMP_H */
131