Update ia64 patch to 2.5.69-030521, throwing away the parts included
[linux-flexiantxendom0-3.2.10.git] / include / asm-ia64 / sn / addrs.h
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (c) 1992-1999,2001-2003 Silicon Graphics, Inc. All rights reserved.
7  */
8
9 #ifndef _ASM_IA64_SN_ADDRS_H
10 #define _ASM_IA64_SN_ADDRS_H
11
12 #include <linux/config.h>
13
14 #include <asm/sn/sn2/addrs.h>
15
16 #ifndef __ASSEMBLY__
17 #include <asm/sn/types.h>
18 #endif 
19
20 #ifndef __ASSEMBLY__
21
22 #define PS_UINT_CAST            (__psunsigned_t)
23 #define UINT64_CAST             (uint64_t)
24 #define HUBREG_CAST             (volatile mmr_t *)
25
26 #elif __ASSEMBLY__
27
28 #define PS_UINT_CAST
29 #define UINT64_CAST
30 #define HUBREG_CAST
31
32 #endif
33
34
35
36
37 /*
38  * The following macros are used to index to the beginning of a specific
39  * node's address space.
40  */
41
42 #define NODE_OFFSET(_n)         (UINT64_CAST (_n) << NASID_SHFT)
43
44 #define NODE_CAC_BASE(_n)       (CAC_BASE  + NODE_OFFSET(_n))
45 #define NODE_HSPEC_BASE(_n)     (HSPEC_BASE + NODE_OFFSET(_n))
46 #define NODE_IO_BASE(_n)        (IO_BASE    + NODE_OFFSET(_n))
47 #define NODE_MSPEC_BASE(_n)     (MSPEC_BASE + NODE_OFFSET(_n))
48 #define NODE_UNCAC_BASE(_n)     (UNCAC_BASE + NODE_OFFSET(_n))
49
50 #define TO_NODE(_n, _x)         (NODE_OFFSET(_n)     | ((_x)               ))
51 #define TO_NODE_CAC(_n, _x)     (NODE_CAC_BASE(_n) | ((_x) & TO_PHYS_MASK))
52 #define TO_NODE_UNCAC(_n, _x)   (NODE_UNCAC_BASE(_n) | ((_x) & TO_PHYS_MASK))
53 #define TO_NODE_MSPEC(_n, _x)   (NODE_MSPEC_BASE(_n) | ((_x) & TO_PHYS_MASK))
54 #define TO_NODE_HSPEC(_n, _x)   (NODE_HSPEC_BASE(_n) | ((_x) & TO_PHYS_MASK))
55
56
57 #define RAW_NODE_SWIN_BASE(nasid, widget)                               \
58         (NODE_IO_BASE(nasid) + (UINT64_CAST (widget) << SWIN_SIZE_BITS))
59
60 #define WIDGETID_GET(addr)      ((unsigned char)((addr >> SWIN_SIZE_BITS) & 0xff))
61
62 /*
63  * The following definitions pertain to the IO special address
64  * space.  They define the location of the big and little windows
65  * of any given node.
66  */
67
68 #define SWIN_SIZE_BITS          24
69 #define SWIN_SIZE               (1UL<<24)
70 #define SWIN_SIZEMASK           (SWIN_SIZE - 1)
71 #define SWIN_WIDGET_MASK        0xF
72
73 /*
74  * Convert smallwindow address to xtalk address.
75  *
76  * 'addr' can be physical or virtual address, but will be converted
77  * to Xtalk address in the range 0 -> SWINZ_SIZEMASK
78  */
79 #define SWIN_WIDGETADDR(addr)   ((addr) & SWIN_SIZEMASK)
80 #define SWIN_WIDGETNUM(addr)    (((addr)  >> SWIN_SIZE_BITS) & SWIN_WIDGET_MASK)
81 /*
82  * Verify if addr belongs to small window address on node with "nasid"
83  *
84  *
85  * NOTE: "addr" is expected to be XKPHYS address, and NOT physical
86  * address
87  *
88  *
89  */
90 #define NODE_SWIN_ADDR(nasid, addr)     \
91                 (((addr) >= NODE_SWIN_BASE(nasid, 0))  && \
92                  ((addr) <  (NODE_SWIN_BASE(nasid, HUB_NUM_WIDGET) + SWIN_SIZE)\
93                  ))
94
95 /*
96  * The following define the major position-independent aliases used
97  * in SN.
98  *      LBOOT  -- 256MB in size, reads in the LBOOT area result in
99  *                      uncached references to the local hub's boot prom and
100  *                      other directory-bus connected devices.
101  *      IALIAS -- 8MB in size, reads in the IALIAS result in uncached
102  *                      references to the local hub's registers.
103  */
104
105 #define HUB_REGISTER_WIDGET     1
106 #define IALIAS_BASE             LOCAL_SWIN_BASE(HUB_REGISTER_WIDGET)
107 #define IALIAS_SIZE             0x800000        /* 8 Megabytes */
108 #define IS_IALIAS(_a)           (((_a) >= IALIAS_BASE) &&               \
109                                  ((_a) < (IALIAS_BASE + IALIAS_SIZE)))
110
111 /*
112  * The following macros produce the correct base virtual address for
113  * the hub registers.  The LOCAL_HUB_* macros produce the appropriate
114  * address for the local registers.  The REMOTE_HUB_* macro produce
115  * the address for the specified hub's registers.  The intent is
116  * that the appropriate PI, MD, NI, or II register would be substituted
117  * for _x.
118  */
119
120
121 /*
122  * SN2 has II mmr's located inside small window space.
123  * As all other non-II mmr's located at the top of big window
124  * space.
125  */
126 #define LOCAL_HUB_BASE(_x)      (LOCAL_MMR_ADDR(_x) | (((~(_x)) & BWIN_TOP)>>8))
127 #define REMOTE_HUB_BASE(_x)                                             \
128         (UNCACHED | GLOBAL_MMR_SPACE |                                  \
129         (((~(_x)) & BWIN_TOP)>>8)    |                                       \
130         (((~(_x)) & BWIN_TOP)>>9)    | (_x))
131
132 #define LOCAL_HUB(_x) (HUBREG_CAST LOCAL_HUB_BASE(_x))
133 #define REMOTE_HUB(_n, _x)                                              \
134         (HUBREG_CAST (REMOTE_HUB_BASE(_x) | ((((long)(_n))<<NASID_SHFT))))
135
136
137 /*
138  * WARNING:
139  *      When certain Hub chip workaround are defined, it's not sufficient
140  *      to dereference the *_HUB_ADDR() macros.  You should instead use
141  *      HUB_L() and HUB_S() if you must deal with pointers to hub registers.
142  *      Otherwise, the recommended approach is to use *_HUB_L() and *_HUB_S().
143  *      They're always safe.
144  */
145 #define LOCAL_HUB_ADDR(_x)                                                      \
146         (((_x) & BWIN_TOP) ? (HUBREG_CAST (LOCAL_MMR_ADDR(_x)))         \
147         : (HUBREG_CAST (IALIAS_BASE + (_x))))
148 #define REMOTE_HUB_ADDR(_n, _x)                                         \
149         (((_x) & BWIN_TOP) ? (HUBREG_CAST (GLOBAL_MMR_ADDR(_n, _x)))    \
150         : (HUBREG_CAST (NODE_SWIN_BASE(_n, 1) + 0x800000 + (_x))))
151
152 #ifndef __ASSEMBLY__
153
154 #define HUB_L(_a)                       (*((volatile typeof(*_a) *)_a))
155 #define HUB_S(_a, _d)                   (*((volatile typeof(*_a) *)_a) = (_d))
156
157 #define LOCAL_HUB_L(_r)                 HUB_L(LOCAL_HUB_ADDR(_r))
158 #define LOCAL_HUB_S(_r, _d)             HUB_S(LOCAL_HUB_ADDR(_r), (_d))
159 #define REMOTE_HUB_L(_n, _r)            HUB_L(REMOTE_HUB_ADDR((_n), (_r)))
160 #define REMOTE_HUB_S(_n, _r, _d)        HUB_S(REMOTE_HUB_ADDR((_n), (_r)), (_d))
161 #define REMOTE_HUB_PI_L(_n, _sn, _r)    HUB_L(REMOTE_HUB_PI_ADDR((_n), (_sn), (_r)))
162 #define REMOTE_HUB_PI_S(_n, _sn, _r, _d) HUB_S(REMOTE_HUB_PI_ADDR((_n), (_sn), (_r)), (_d))
163
164 #endif /* __ASSEMBLY__ */
165
166 /*
167  * The following macros are used to get to a hub/bridge register, given
168  * the base of the register space.
169  */
170 #define HUB_REG_PTR(_base, _off)        \
171         (HUBREG_CAST ((__psunsigned_t)(_base) + (__psunsigned_t)(_off)))
172
173 #define HUB_REG_PTR_L(_base, _off)      \
174         HUB_L(HUB_REG_PTR((_base), (_off)))
175
176 #define HUB_REG_PTR_S(_base, _off, _data)       \
177         HUB_S(HUB_REG_PTR((_base), (_off)), (_data))
178
179 /*
180  * Software structure locations -- permanently fixed
181  *    See diagram in kldir.h
182  */
183
184 #define PHYS_RAMBASE            0x0
185 #define K0_RAMBASE              PHYS_TO_K0(PHYS_RAMBASE)
186
187 #define ARCS_SPB_OFFSET         0x1000
188 #define ARCS_SPB_ADDR(nasid)                                            \
189         PHYS_TO_K0(NODE_OFFSET(nasid) | ARCS_SPB_OFFSET)
190 #define ARCS_SPB_SIZE           0x0400
191
192 #define KLDIR_OFFSET            0x2000
193 #define KLDIR_ADDR(nasid)                                               \
194         TO_NODE_CAC((nasid), KLDIR_OFFSET)
195 #define KLDIR_SIZE              0x0400
196
197
198 /*
199  * Software structure locations -- indirected through KLDIR
200  *    See diagram in kldir.h
201  *
202  * Important:   All low memory structures must only be accessed
203  *              uncached, except for the symmon stacks.
204  */
205
206 #define KLI_LAUNCH              0               /* Dir. entries */
207 #define KLI_KLCONFIG            1
208 #define KLI_NMI                 2
209 #define KLI_GDA                 3
210 #define KLI_FREEMEM             4
211 #define KLI_SYMMON_STK          5
212 #define KLI_PI_ERROR            6
213 #define KLI_KERN_VARS           7
214 #define KLI_KERN_XP             8
215 #define KLI_KERN_PARTID         9
216
217 #ifndef __ASSEMBLY__
218
219 #define KLD_BASE(nasid)         ((kldir_ent_t *) KLDIR_ADDR(nasid))
220 #define KLD_LAUNCH(nasid)       (KLD_BASE(nasid) + KLI_LAUNCH)
221 #define KLD_NMI(nasid)          (KLD_BASE(nasid) + KLI_NMI)
222 #define KLD_KLCONFIG(nasid)     (KLD_BASE(nasid) + KLI_KLCONFIG)
223 #define KLD_PI_ERROR(nasid)     (KLD_BASE(nasid) + KLI_PI_ERROR)
224 #define KLD_GDA(nasid)          (KLD_BASE(nasid) + KLI_GDA)
225 #define KLD_SYMMON_STK(nasid)   (KLD_BASE(nasid) + KLI_SYMMON_STK)
226 #define KLD_FREEMEM(nasid)      (KLD_BASE(nasid) + KLI_FREEMEM)
227 #define KLD_KERN_VARS(nasid)    (KLD_BASE(nasid) + KLI_KERN_VARS)
228 #define KLD_KERN_XP(nasid)      (KLD_BASE(nasid) + KLI_KERN_XP)
229 #define KLD_KERN_PARTID(nasid)  (KLD_BASE(nasid) + KLI_KERN_PARTID)
230
231 #define KLCONFIG_OFFSET(nasid)  ia64_sn_get_klconfig_addr(nasid)
232
233 #define KLCONFIG_ADDR(nasid)                                            \
234         TO_NODE_CAC((nasid), KLCONFIG_OFFSET(nasid))
235 #define KLCONFIG_SIZE(nasid)    KLD_KLCONFIG(nasid)->size
236
237 #define GDA_ADDR(nasid)         KLD_GDA(nasid)->pointer
238 #define GDA_SIZE(nasid)         KLD_GDA(nasid)->size
239
240 #define NODE_OFFSET_TO_K0(_nasid, _off)                                 \
241         (CACHEABLE_MEM_SPACE | NODE_OFFSET(_nasid) | (_off))
242
243 #endif /* __ASSEMBLY__ */
244
245 #endif /* _ASM_IA64_SN_ADDRS_H */