ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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_logical_id(cpu)                             0
88 #define cpu_physical_id(cpuid)                  ((ia64_getreg(_IA64_REG_CR_LID) >> 16) & 0xffff)
89 #endif
90
91 /*
92  * macros for some of these exist in sn/addrs.h & sn/arch.h, etc. However, 
93  * trying #include these files here causes circular dependencies.
94  */
95 #define cpu_physical_id_to_nasid(cpi)           ((cpi) &0xfff)
96 #define cpu_physical_id_to_slice(cpi)           ((cpi>>12) & 3)
97 #define get_nasid()                             ((ia64_getreg(_IA64_REG_CR_LID) >> 16) & 0xfff)
98 #define get_slice()                             ((ia64_getreg(_IA64_REG_CR_LID) >> 28) & 0xf)
99 #define get_node_number(addr)                   (((unsigned long)(addr)>>38) & 0x7ff)
100
101 /*
102  * NOTE: id & eid refer to Intel's definitions of the LID register
103  * 
104  * NOTE: on non-MP systems, only cpuid 0 exists
105  */
106 #define id_eid_to_cpu_physical_id(id,eid)               (((id)<<8) | (eid))
107
108 #define nasid_slice_to_cpuid(nasid,slice)               (cpu_logical_id(nasid_slice_to_cpu_physical_id((nasid),(slice))))
109
110 #define nasid_slice_to_cpu_physical_id(nasid, slice)    (((slice)<<12) | (nasid))
111
112 /*
113  * The following table/struct  is used for managing PTC coherency domains.
114  */
115 typedef struct {
116         u8      domain;
117         u8      reserved;
118         u16     sapicid;
119 } sn_sapicid_info_t;
120
121 extern sn_sapicid_info_t        sn_sapicid_info[];      /* indexed by cpuid */
122 extern short physical_node_map[];                       /* indexed by nasid to get cnode */
123
124
125 /*
126  * cpuid_to_slice  - convert a cpuid to the slice that it resides on
127  *  There are 4 cpus per node. This function returns 0 .. 3)
128  */
129 #define cpuid_to_slice(cpuid)           (cpu_physical_id_to_slice(cpu_physical_id(cpuid)))
130
131
132 /*
133  * cpuid_to_nasid  - convert a cpuid to the NASID that it resides on
134  */
135 #define cpuid_to_nasid(cpuid)           (cpu_physical_id_to_nasid(cpu_physical_id(cpuid)))
136
137
138 /*
139  * cpuid_to_cnodeid  - convert a cpuid to the cnode that it resides on
140  */
141 #define cpuid_to_cnodeid(cpuid)         (physical_node_map[cpuid_to_nasid(cpuid)])
142
143
144 /*
145  * cnodeid_to_nasid - convert a cnodeid to a NASID
146  *      Macro relies on pg_data for a node being on the node itself.
147  *      Just extract the NASID from the pointer.
148  *
149  */
150 #define cnodeid_to_nasid(cnodeid)       pda->cnodeid_to_nasid_table[cnodeid]
151  
152
153 /*
154  * nasid_to_cnodeid - convert a NASID to a cnodeid
155  */
156 #define nasid_to_cnodeid(nasid)         (physical_node_map[nasid])
157
158
159 /*
160  * cnode_slice_to_cpuid - convert a codeid & slice to a cpuid
161  */
162
163 #define cnode_slice_to_cpuid(cnodeid,slice) (nasid_slice_to_cpuid(cnodeid_to_nasid(cnodeid),(slice)))
164  
165
166 /*
167  * cpuid_to_subnode - convert a cpuid to the subnode it resides on.
168  *   slice 0 & 1 are on subnode 0
169  *   slice 2 & 3 are on subnode 1.
170  */
171 #define cpuid_to_subnode(cpuid)         ((cpuid_to_slice(cpuid)<2) ? 0 : 1)
172  
173
174 #define smp_physical_node_id()                  (cpuid_to_nasid(smp_processor_id()))
175
176
177 #endif /* _ASM_IA64_SN_SN_CPUID_H */
178