VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / include / asm-ia64 / sn / sn_cpuid.h
1 /* 
2  *
3  * This file is subject to the terms and conditions of the GNU General Public
4  * License.  See the file "COPYING" in the main directory of this archive
5  * for more details.
6  *
7  * Copyright (C) 2000-2003 Silicon Graphics, Inc. All rights reserved.
8  */
9
10
11 #ifndef _ASM_IA64_SN_SN_CPUID_H
12 #define _ASM_IA64_SN_SN_CPUID_H
13
14 #include <linux/config.h>
15 #include <linux/smp.h>
16 #include <asm/sn/pda.h>
17 #include <asm/intrinsics.h>
18
19
20 /*
21  * Functions for converting between cpuids, nodeids and NASIDs.
22  * 
23  * These are for SGI platforms only.
24  *
25  */
26
27
28
29
30 /*
31  *  Definitions of terms (these definitions are for IA64 ONLY. Other architectures
32  *  use cpuid/cpunum quite defferently):
33  *
34  *         CPUID - a number in range of 0..NR_CPUS-1 that uniquely identifies
35  *              the cpu. The value cpuid has no significance on IA64 other than
36  *              the boot cpu is 0.
37  *                      smp_processor_id() returns the cpuid of the current cpu.
38  *
39  *         CPUNUM - On IA64, a cpunum and cpuid are the same. This is NOT true
40  *              on other architectures like IA32.
41  *
42  *         CPU_PHYSICAL_ID (also known as HARD_PROCESSOR_ID)
43  *              This is the same as 31:24 of the processor LID register
44  *                      hard_smp_processor_id()- cpu_physical_id of current processor
45  *                      cpu_physical_id(cpuid) - convert a <cpuid> to a <physical_cpuid>
46  *                      cpu_logical_id(phy_id) - convert a <physical_cpuid> to a <cpuid> 
47  *                              * not real efficient - don't use in perf critical code
48  *
49  *         LID - processor defined register (see PRM V2).
50  *
51  *           On SN2
52  *              31:28 - id   Contains 0-3 to identify the cpu on the node
53  *              27:16 - eid  Contains the NASID
54  *
55  *
56  *
57  * The following assumes the following mappings for LID register values:
58  *
59  * The macros convert between cpu physical ids & slice/nasid/cnodeid.
60  * These terms are described below:
61  *
62  *
63  * Brick
64  *          -----   -----           -----   -----       CPU
65  *          | 0 |   | 1 |           | 0 |   | 1 |       SLICE
66  *          -----   -----           -----   -----
67  *            |       |               |       |
68  *            |       |               |       |
69  *          0 |       | 2           0 |       | 2       FSB SLOT
70  *             -------                 -------  
71  *                |                       |
72  *                |                       |
73  *                |                       |
74  *             ------------      -------------
75  *             |          |      |           |
76  *             |    SHUB  |      |   SHUB    |        NASID   (0..MAX_NASIDS)
77  *             |          |----- |           |        CNODEID (0..num_compact_nodes-1)
78  *             |          |      |           |
79  *             |          |      |           |
80  *             ------------      -------------
81  *                   |                 |
82  *                           
83  *
84  */
85
86 #ifndef CONFIG_SMP
87 #define cpu_physical_id(cpuid)                  ((ia64_getreg(_IA64_REG_CR_LID) >> 16) & 0xffff)
88 #endif
89
90 /*
91  * macros for some of these exist in sn/addrs.h & sn/arch.h, etc. However, 
92  * trying #include these files here causes circular dependencies.
93  */
94 #define cpu_physical_id_to_nasid(cpi)           ((cpi) &0xfff)
95 #define cpu_physical_id_to_slice(cpi)           ((cpi>>12) & 3)
96 #define get_nasid()                             ((ia64_getreg(_IA64_REG_CR_LID) >> 16) & 0xfff)
97 #define get_slice()                             ((ia64_getreg(_IA64_REG_CR_LID) >> 28) & 0xf)
98 #define get_node_number(addr)                   (((unsigned long)(addr)>>38) & 0x7ff)
99
100 /*
101  * NOTE: id & eid refer to Intel's definitions of the LID register
102  * 
103  * NOTE: on non-MP systems, only cpuid 0 exists
104  */
105 #define id_eid_to_cpu_physical_id(id,eid)               (((id)<<8) | (eid))
106
107 #define nasid_slice_to_cpuid(nasid,slice)               (cpu_logical_id(nasid_slice_to_cpu_physical_id((nasid),(slice))))
108
109 #define nasid_slice_to_cpu_physical_id(nasid, slice)    (((slice)<<12) | (nasid))
110
111 /*
112  * The following table/struct  is used for managing PTC coherency domains.
113  */
114 typedef struct {
115         u8      domain;
116         u8      reserved;
117         u16     sapicid;
118 } sn_sapicid_info_t;
119
120 extern sn_sapicid_info_t        sn_sapicid_info[];      /* indexed by cpuid */
121 extern short physical_node_map[];                       /* indexed by nasid to get cnode */
122
123
124 /*
125  * cpuid_to_slice  - convert a cpuid to the slice that it resides on
126  *  There are 4 cpus per node. This function returns 0 .. 3)
127  */
128 #define cpuid_to_slice(cpuid)           (cpu_physical_id_to_slice(cpu_physical_id(cpuid)))
129
130
131 /*
132  * cpuid_to_nasid  - convert a cpuid to the NASID that it resides on
133  */
134 #define cpuid_to_nasid(cpuid)           (cpu_physical_id_to_nasid(cpu_physical_id(cpuid)))
135
136
137 /*
138  * cpuid_to_cnodeid  - convert a cpuid to the cnode that it resides on
139  */
140 #define cpuid_to_cnodeid(cpuid)         (physical_node_map[cpuid_to_nasid(cpuid)])
141
142
143 /*
144  * cnodeid_to_nasid - convert a cnodeid to a NASID
145  *      Macro relies on pg_data for a node being on the node itself.
146  *      Just extract the NASID from the pointer.
147  *
148  */
149 #define cnodeid_to_nasid(cnodeid)       pda->cnodeid_to_nasid_table[cnodeid]
150  
151
152 /*
153  * nasid_to_cnodeid - convert a NASID to a cnodeid
154  */
155 #define nasid_to_cnodeid(nasid)         (physical_node_map[nasid])
156
157
158 /*
159  * cnode_slice_to_cpuid - convert a codeid & slice to a cpuid
160  */
161
162 #define cnode_slice_to_cpuid(cnodeid,slice) (nasid_slice_to_cpuid(cnodeid_to_nasid(cnodeid),(slice)))
163  
164
165 /*
166  * cpuid_to_subnode - convert a cpuid to the subnode it resides on.
167  *   slice 0 & 1 are on subnode 0
168  *   slice 2 & 3 are on subnode 1.
169  */
170 #define cpuid_to_subnode(cpuid)         ((cpuid_to_slice(cpuid)<2) ? 0 : 1)
171  
172
173 #define smp_physical_node_id()                  (cpuid_to_nasid(smp_processor_id()))
174
175
176 #endif /* _ASM_IA64_SN_SN_CPUID_H */
177