Linux Audio

Check our new training course

Loading...
v5.4
  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 - 1997, 1999, 2000 Silicon Graphics, Inc.
  7 * Copyright (C) 1999, 2000 by Ralf Baechle
  8 */
  9#ifndef _ASM_SN_ADDRS_H
 10#define _ASM_SN_ADDRS_H
 11
 12
 13#ifndef __ASSEMBLY__
 14#include <linux/smp.h>
 15#include <linux/types.h>
 16#endif /* !__ASSEMBLY__ */
 17
 18#include <asm/addrspace.h>
 19#include <asm/sn/kldir.h>
 20
 21#if defined(CONFIG_SGI_IP27)
 22#include <asm/sn/sn0/addrs.h>
 23#elif defined(CONFIG_SGI_IP35)
 24#include <asm/sn/sn1/addrs.h>
 25#endif
 26
 27
 28#ifndef __ASSEMBLY__
 29
 
 30#define UINT64_CAST		(unsigned long)
 31
 
 
 32#else /* __ASSEMBLY__ */
 33
 
 34#define UINT64_CAST
 
 35
 36#endif /* __ASSEMBLY__ */
 37
 38
 39#define NASID_GET_META(_n)	((_n) >> NASID_LOCAL_BITS)
 40#ifdef CONFIG_SGI_IP27
 41#define NASID_GET_LOCAL(_n)	((_n) & 0xf)
 42#endif
 43#define NASID_MAKE(_m, _l)	(((_m) << NASID_LOCAL_BITS) | (_l))
 44
 45#define NODE_ADDRSPACE_MASK	(NODE_ADDRSPACE_SIZE - 1)
 46#define TO_NODE_ADDRSPACE(_pa)	(UINT64_CAST (_pa) & NODE_ADDRSPACE_MASK)
 47
 48#define CHANGE_ADDR_NASID(_pa, _nasid)	\
 49		((UINT64_CAST(_pa) & ~NASID_MASK) | \
 50		 (UINT64_CAST(_nasid) <<  NASID_SHFT))
 51
 52
 53/*
 54 * The following macros are used to index to the beginning of a specific
 55 * node's address space.
 56 */
 57
 58#define NODE_OFFSET(_n)		(UINT64_CAST (_n) << NODE_SIZE_BITS)
 59
 60#define NODE_CAC_BASE(_n)	(CAC_BASE   + NODE_OFFSET(_n))
 61#define NODE_HSPEC_BASE(_n)	(HSPEC_BASE + NODE_OFFSET(_n))
 62#define NODE_IO_BASE(_n)	(IO_BASE    + NODE_OFFSET(_n))
 63#define NODE_MSPEC_BASE(_n)	(MSPEC_BASE + NODE_OFFSET(_n))
 64#define NODE_UNCAC_BASE(_n)	(UNCAC_BASE + NODE_OFFSET(_n))
 65
 66#define TO_NODE(_n, _x)		(NODE_OFFSET(_n)     | ((_x)		   ))
 67#define TO_NODE_CAC(_n, _x)	(NODE_CAC_BASE(_n)   | ((_x) & TO_PHYS_MASK))
 68#define TO_NODE_UNCAC(_n, _x)	(NODE_UNCAC_BASE(_n) | ((_x) & TO_PHYS_MASK))
 69#define TO_NODE_MSPEC(_n, _x)	(NODE_MSPEC_BASE(_n) | ((_x) & TO_PHYS_MASK))
 70#define TO_NODE_HSPEC(_n, _x)	(NODE_HSPEC_BASE(_n) | ((_x) & TO_PHYS_MASK))
 71
 72
 73#define RAW_NODE_SWIN_BASE(nasid, widget)				\
 74	(NODE_IO_BASE(nasid) + (UINT64_CAST(widget) << SWIN_SIZE_BITS))
 75
 76#define WIDGETID_GET(addr)	((unsigned char)((addr >> SWIN_SIZE_BITS) & 0xff))
 77
 78/*
 79 * The following definitions pertain to the IO special address
 80 * space.  They define the location of the big and little windows
 81 * of any given node.
 82 */
 83
 84#define SWIN_SIZE_BITS		24
 85#define SWIN_SIZE		(UINT64_CAST 1 << 24)
 86#define SWIN_SIZEMASK		(SWIN_SIZE - 1)
 87#define SWIN_WIDGET_MASK	0xF
 88
 89/*
 90 * Convert smallwindow address to xtalk address.
 91 *
 92 * 'addr' can be physical or virtual address, but will be converted
 93 * to Xtalk address in the range 0 -> SWINZ_SIZEMASK
 94 */
 95#define SWIN_WIDGETADDR(addr)	((addr) & SWIN_SIZEMASK)
 96#define SWIN_WIDGETNUM(addr)	(((addr)  >> SWIN_SIZE_BITS) & SWIN_WIDGET_MASK)
 97/*
 98 * Verify if addr belongs to small window address on node with "nasid"
 99 *
100 *
101 * NOTE: "addr" is expected to be XKPHYS address, and NOT physical
102 * address
103 *
104 *
105 */
106#define NODE_SWIN_ADDR(nasid, addr)	\
107		(((addr) >= NODE_SWIN_BASE(nasid, 0))  && \
108		 ((addr) <  (NODE_SWIN_BASE(nasid, HUB_NUM_WIDGET) + SWIN_SIZE)\
109		 ))
110
111/*
112 * The following define the major position-independent aliases used
113 * in SN.
114 *	UALIAS -- 256MB in size, reads in the UALIAS result in
115 *			uncached references to the memory of the reader's node.
116 *	CPU_UALIAS -- 128kb in size, the bottom part of UALIAS is flipped
117 *			depending on which CPU does the access to provide
118 *			all CPUs with unique uncached memory at low addresses.
119 *	LBOOT  -- 256MB in size, reads in the LBOOT area result in
120 *			uncached references to the local hub's boot prom and
121 *			other directory-bus connected devices.
122 *	IALIAS -- 8MB in size, reads in the IALIAS result in uncached
123 *			references to the local hub's registers.
124 */
125
126#define UALIAS_BASE		HSPEC_BASE
127#define UALIAS_SIZE		0x10000000	/* 256 Megabytes */
128#define UALIAS_LIMIT		(UALIAS_BASE + UALIAS_SIZE)
129
130/*
131 * The bottom of ualias space is flipped depending on whether you're
132 * processor 0 or 1 within a node.
133 */
134#ifdef CONFIG_SGI_IP27
135#define UALIAS_FLIP_BASE	UALIAS_BASE
136#define UALIAS_FLIP_SIZE	0x20000
137#define UALIAS_FLIP_BIT		0x10000
138#define UALIAS_FLIP_ADDR(_x)	(cputoslice(smp_processor_id()) ? \
139				 (_x) ^ UALIAS_FLIP_BIT : (_x))
140
141#define LBOOT_BASE		(HSPEC_BASE + 0x10000000)
142#define LBOOT_SIZE		0x10000000
143#define LBOOT_LIMIT		(LBOOT_BASE + LBOOT_SIZE)
144#define LBOOT_STRIDE		0		/* IP27 has only one CPU PROM */
145
146#endif
147
148#define HUB_REGISTER_WIDGET	1
149#define IALIAS_BASE		NODE_SWIN_BASE(0, HUB_REGISTER_WIDGET)
150#define IALIAS_SIZE		0x800000	/* 8 Megabytes */
151#define IS_IALIAS(_a)		(((_a) >= IALIAS_BASE) &&		\
152				 ((_a) < (IALIAS_BASE + IALIAS_SIZE)))
153
154/*
155 * Macro for referring to Hub's RBOOT space
156 */
157
158#ifdef CONFIG_SGI_IP27
159#define RBOOT_SIZE		0x10000000	/* 256 Megabytes */
160#define NODE_RBOOT_BASE(_n)	(NODE_HSPEC_BASE(_n) + 0x30000000)
161#define NODE_RBOOT_LIMIT(_n)	(NODE_RBOOT_BASE(_n) + RBOOT_SIZE)
162
163#endif
164
165/*
166 * Macros for referring the Hub's back door space
167 *
168 *   These macros correctly process addresses in any node's space.
169 *   WARNING: They won't work in assembler.
170 *
171 *   BDDIR_ENTRY_LO returns the address of the low double-word of the dir
172 *		    entry corresponding to a physical (Cac or Uncac) address.
173 *   BDDIR_ENTRY_HI returns the address of the high double-word of the entry.
174 *   BDPRT_ENTRY    returns the address of the double-word protection entry
175 *		    corresponding to the page containing the physical address.
176 *   BDPRT_ENTRY_S  Stores the value into the protection entry.
177 *   BDPRT_ENTRY_L  Load the value from the protection entry.
178 *   BDECC_ENTRY    returns the address of the ECC byte corresponding to a
179 *		    double-word at a specified physical address.
180 *   BDECC_ENTRY_H  returns the address of the two ECC bytes corresponding to a
181 *		    quad-word at a specified physical address.
182 */
183#define NODE_BDOOR_BASE(_n)	(NODE_HSPEC_BASE(_n) + (NODE_ADDRSPACE_SIZE/2))
184
185#define NODE_BDECC_BASE(_n)	(NODE_BDOOR_BASE(_n))
186#define NODE_BDDIR_BASE(_n)	(NODE_BDOOR_BASE(_n) + (NODE_ADDRSPACE_SIZE/4))
187#ifdef CONFIG_SGI_IP27
188#define BDDIR_ENTRY_LO(_pa)	((HSPEC_BASE +				      \
189				  NODE_ADDRSPACE_SIZE * 3 / 4 +		      \
190				  0x200)				    | \
191				 UINT64_CAST(_pa)	 & NASID_MASK	    | \
192				 UINT64_CAST(_pa) >> 2 & BDDIR_UPPER_MASK  | \
193				 UINT64_CAST(_pa) >> 3 & 0x1f << 4)
194
195#define BDDIR_ENTRY_HI(_pa)	((HSPEC_BASE +				      \
196				  NODE_ADDRSPACE_SIZE * 3 / 4 +		      \
197				  0x208)				    | \
198				 UINT64_CAST(_pa)	 & NASID_MASK	    | \
199				 UINT64_CAST(_pa) >> 2 & BDDIR_UPPER_MASK  | \
200				 UINT64_CAST(_pa) >> 3 & 0x1f << 4)
201
202#define BDPRT_ENTRY(_pa, _rgn)	((HSPEC_BASE +				      \
203				  NODE_ADDRSPACE_SIZE * 3 / 4)		    | \
204				 UINT64_CAST(_pa)	 & NASID_MASK	    | \
205				 UINT64_CAST(_pa) >> 2 & BDDIR_UPPER_MASK  | \
206				 (_rgn) << 3)
207#define BDPRT_ENTRY_ADDR(_pa, _rgn) (BDPRT_ENTRY((_pa), (_rgn)))
208#define BDPRT_ENTRY_S(_pa, _rgn, _val) (*(__psunsigned_t *)BDPRT_ENTRY((_pa), (_rgn))=(_val))
209#define BDPRT_ENTRY_L(_pa, _rgn)	(*(__psunsigned_t *)BDPRT_ENTRY((_pa), (_rgn)))
210
211#define BDECC_ENTRY(_pa)	((HSPEC_BASE +				      \
212				  NODE_ADDRSPACE_SIZE / 2)		    | \
213				 UINT64_CAST(_pa)	 & NASID_MASK	    | \
214				 UINT64_CAST(_pa) >> 2 & BDECC_UPPER_MASK  | \
215				 UINT64_CAST(_pa) >> 3 & 3)
216
217/*
218 * Macro to convert a back door directory or protection address into the
219 *   raw physical address of the associated cache line or protection page.
220 */
221#define BDADDR_IS_DIR(_ba)	((UINT64_CAST  (_ba) & 0x200) != 0)
222#define BDADDR_IS_PRT(_ba)	((UINT64_CAST  (_ba) & 0x200) == 0)
223
224#define BDDIR_TO_MEM(_ba)	(UINT64_CAST (_ba) & NASID_MASK		   | \
225				 (UINT64_CAST(_ba) & BDDIR_UPPER_MASK)<<2  | \
226				 (UINT64_CAST(_ba) & 0x1f << 4) << 3)
227
228#define BDPRT_TO_MEM(_ba)	(UINT64_CAST (_ba) & NASID_MASK	    | \
229				 (UINT64_CAST(_ba) & BDDIR_UPPER_MASK)<<2)
230
231#define BDECC_TO_MEM(_ba)	(UINT64_CAST (_ba) & NASID_MASK	    | \
232				 (UINT64_CAST(_ba) & BDECC_UPPER_MASK)<<2  | \
233				 (UINT64_CAST(_ba) & 3) << 3)
234#endif /* CONFIG_SGI_IP27 */
235
236
237/*
238 * The following macros produce the correct base virtual address for
239 * the hub registers.  The LOCAL_HUB_* macros produce the appropriate
240 * address for the local registers.  The REMOTE_HUB_* macro produce
241 * the address for the specified hub's registers.  The intent is
242 * that the appropriate PI, MD, NI, or II register would be substituted
243 * for _x.
244 */
245
246/*
247 * WARNING:
248 *	When certain Hub chip workaround are defined, it's not sufficient
249 *	to dereference the *_HUB_ADDR() macros.	 You should instead use
250 *	HUB_L() and HUB_S() if you must deal with pointers to hub registers.
251 *	Otherwise, the recommended approach is to use *_HUB_L() and *_HUB_S().
252 *	They're always safe.
253 */
254#define LOCAL_HUB_ADDR(_x)	(IALIAS_BASE + (_x))
255#define REMOTE_HUB_ADDR(_n, _x) ((NODE_SWIN_BASE(_n, 1) + 0x800000 + (_x)))
 
 
 
 
 
256
257#ifndef __ASSEMBLY__
258
259#define LOCAL_HUB_PTR(_x)	((u64 *)LOCAL_HUB_ADDR((_x)))
260#define REMOTE_HUB_PTR(_n, _x)	((u64 *)REMOTE_HUB_ADDR((_n), (_x)))
261
262#define LOCAL_HUB_L(_r)			__raw_readq(LOCAL_HUB_PTR(_r))
263#define LOCAL_HUB_S(_r, _d)		__raw_writeq((_d), LOCAL_HUB_PTR(_r))
264#define REMOTE_HUB_L(_n, _r)		__raw_readq(REMOTE_HUB_PTR((_n), (_r)))
265#define REMOTE_HUB_S(_n, _r, _d)	__raw_writeq((_d),		\
266						REMOTE_HUB_PTR((_n), (_r)))
 
267
268#endif /* !__ASSEMBLY__ */
269
270/*
 
 
 
 
 
 
 
 
 
 
 
 
 
271 * Software structure locations -- permanently fixed
272 *    See diagram in kldir.h
273 */
274
275#define PHYS_RAMBASE		0x0
276#define K0_RAMBASE		PHYS_TO_K0(PHYS_RAMBASE)
277
278#define EX_HANDLER_OFFSET(slice) ((slice) << 16)
279#define EX_HANDLER_ADDR(nasid, slice)					\
280	PHYS_TO_K0(NODE_OFFSET(nasid) | EX_HANDLER_OFFSET(slice))
281#define EX_HANDLER_SIZE		0x0400
282
283#define EX_FRAME_OFFSET(slice)	((slice) << 16 | 0x400)
284#define EX_FRAME_ADDR(nasid, slice)					\
285	PHYS_TO_K0(NODE_OFFSET(nasid) | EX_FRAME_OFFSET(slice))
286#define EX_FRAME_SIZE		0x0c00
287
288#define ARCS_SPB_OFFSET		0x1000
289#define ARCS_SPB_ADDR(nasid)						\
290	PHYS_TO_K0(NODE_OFFSET(nasid) | ARCS_SPB_OFFSET)
291#define ARCS_SPB_SIZE		0x0400
292
293#define KLDIR_OFFSET		0x2000
294#define KLDIR_ADDR(nasid)						\
295	TO_NODE_UNCAC((nasid), KLDIR_OFFSET)
296#define KLDIR_SIZE		0x0400
297
298
299/*
300 * Software structure locations -- indirected through KLDIR
301 *    See diagram in kldir.h
302 *
303 * Important:	All low memory structures must only be accessed
304 *		uncached, except for the symmon stacks.
305 */
306
307#define KLI_LAUNCH		0		/* Dir. entries */
308#define KLI_KLCONFIG		1
309#define KLI_NMI			2
310#define KLI_GDA			3
311#define KLI_FREEMEM		4
312#define KLI_SYMMON_STK		5
313#define KLI_PI_ERROR		6
314#define KLI_KERN_VARS		7
315#define KLI_KERN_XP		8
316#define KLI_KERN_PARTID		9
317
318#ifndef __ASSEMBLY__
319
320#define KLD_BASE(nasid)		((kldir_ent_t *) KLDIR_ADDR(nasid))
321#define KLD_LAUNCH(nasid)	(KLD_BASE(nasid) + KLI_LAUNCH)
322#define KLD_NMI(nasid)		(KLD_BASE(nasid) + KLI_NMI)
323#define KLD_KLCONFIG(nasid)	(KLD_BASE(nasid) + KLI_KLCONFIG)
324#define KLD_PI_ERROR(nasid)	(KLD_BASE(nasid) + KLI_PI_ERROR)
325#define KLD_GDA(nasid)		(KLD_BASE(nasid) + KLI_GDA)
326#define KLD_SYMMON_STK(nasid)	(KLD_BASE(nasid) + KLI_SYMMON_STK)
327#define KLD_FREEMEM(nasid)	(KLD_BASE(nasid) + KLI_FREEMEM)
328#define KLD_KERN_VARS(nasid)	(KLD_BASE(nasid) + KLI_KERN_VARS)
329#define KLD_KERN_XP(nasid)	(KLD_BASE(nasid) + KLI_KERN_XP)
330#define KLD_KERN_PARTID(nasid)	(KLD_BASE(nasid) + KLI_KERN_PARTID)
331
332#define LAUNCH_OFFSET(nasid, slice)					\
333	(KLD_LAUNCH(nasid)->offset +					\
334	 KLD_LAUNCH(nasid)->stride * (slice))
335#define LAUNCH_ADDR(nasid, slice)					\
336	TO_NODE_UNCAC((nasid), LAUNCH_OFFSET(nasid, slice))
337#define LAUNCH_SIZE(nasid)	KLD_LAUNCH(nasid)->size
338
339#define SN_NMI_OFFSET(nasid, slice)					\
340	(KLD_NMI(nasid)->offset +					\
341	 KLD_NMI(nasid)->stride * (slice))
342#define NMI_ADDR(nasid, slice)						\
343	TO_NODE_UNCAC((nasid), SN_NMI_OFFSET(nasid, slice))
344#define NMI_SIZE(nasid) KLD_NMI(nasid)->size
345
346#define KLCONFIG_OFFSET(nasid)	KLD_KLCONFIG(nasid)->offset
347#define KLCONFIG_ADDR(nasid)						\
348	TO_NODE_UNCAC((nasid), KLCONFIG_OFFSET(nasid))
349#define KLCONFIG_SIZE(nasid)	KLD_KLCONFIG(nasid)->size
350
351#define GDA_ADDR(nasid)		KLD_GDA(nasid)->pointer
352#define GDA_SIZE(nasid)		KLD_GDA(nasid)->size
353
354#define SYMMON_STK_OFFSET(nasid, slice)					\
355	(KLD_SYMMON_STK(nasid)->offset +				\
356	 KLD_SYMMON_STK(nasid)->stride * (slice))
357#define SYMMON_STK_STRIDE(nasid)	KLD_SYMMON_STK(nasid)->stride
358
359#define SYMMON_STK_ADDR(nasid, slice)					\
360	TO_NODE_CAC((nasid), SYMMON_STK_OFFSET(nasid, slice))
361
362#define SYMMON_STK_SIZE(nasid)	KLD_SYMMON_STK(nasid)->stride
363
364#define SYMMON_STK_END(nasid)	(SYMMON_STK_ADDR(nasid, 0) + KLD_SYMMON_STK(nasid)->size)
365
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366#define NODE_OFFSET_TO_K0(_nasid, _off)					\
367	PHYS_TO_K0((NODE_OFFSET(_nasid) + (_off)) | CAC_BASE)
368#define NODE_OFFSET_TO_K1(_nasid, _off)					\
369	TO_UNCAC((NODE_OFFSET(_nasid) + (_off)) | UNCAC_BASE)
 
 
370
371#define KERN_VARS_ADDR(nasid)	KLD_KERN_VARS(nasid)->pointer
372#define KERN_VARS_SIZE(nasid)	KLD_KERN_VARS(nasid)->size
 
 
 
 
 
373
374#endif /* !__ASSEMBLY__ */
375
376
377#endif /* _ASM_SN_ADDRS_H */
v3.1
  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 - 1997, 1999, 2000 Silicon Graphics, Inc.
  7 * Copyright (C) 1999, 2000 by Ralf Baechle
  8 */
  9#ifndef _ASM_SN_ADDRS_H
 10#define _ASM_SN_ADDRS_H
 11
 12
 13#ifndef __ASSEMBLY__
 14#include <linux/smp.h>
 15#include <linux/types.h>
 16#endif /* !__ASSEMBLY__ */
 17
 18#include <asm/addrspace.h>
 19#include <asm/sn/kldir.h>
 20
 21#if defined(CONFIG_SGI_IP27)
 22#include <asm/sn/sn0/addrs.h>
 23#elif defined(CONFIG_SGI_IP35)
 24#include <asm/sn/sn1/addrs.h>
 25#endif
 26
 27
 28#ifndef __ASSEMBLY__
 29
 30#define PS_UINT_CAST		(unsigned long)
 31#define UINT64_CAST		(unsigned long)
 32
 33#define HUBREG_CAST		(volatile hubreg_t *)
 34
 35#else /* __ASSEMBLY__ */
 36
 37#define PS_UINT_CAST
 38#define UINT64_CAST
 39#define HUBREG_CAST
 40
 41#endif /* __ASSEMBLY__ */
 42
 43
 44#define NASID_GET_META(_n)	((_n) >> NASID_LOCAL_BITS)
 45#ifdef CONFIG_SGI_IP27
 46#define NASID_GET_LOCAL(_n)	((_n) & 0xf)
 47#endif
 48#define NASID_MAKE(_m, _l)	(((_m) << NASID_LOCAL_BITS) | (_l))
 49
 50#define NODE_ADDRSPACE_MASK	(NODE_ADDRSPACE_SIZE - 1)
 51#define TO_NODE_ADDRSPACE(_pa)	(UINT64_CAST (_pa) & NODE_ADDRSPACE_MASK)
 52
 53#define CHANGE_ADDR_NASID(_pa, _nasid)	\
 54		((UINT64_CAST(_pa) & ~NASID_MASK) | \
 55		 (UINT64_CAST(_nasid) <<  NASID_SHFT))
 56
 57
 58/*
 59 * The following macros are used to index to the beginning of a specific
 60 * node's address space.
 61 */
 62
 63#define NODE_OFFSET(_n)		(UINT64_CAST (_n) << NODE_SIZE_BITS)
 64
 65#define NODE_CAC_BASE(_n)	(CAC_BASE   + NODE_OFFSET(_n))
 66#define NODE_HSPEC_BASE(_n)	(HSPEC_BASE + NODE_OFFSET(_n))
 67#define NODE_IO_BASE(_n)	(IO_BASE    + NODE_OFFSET(_n))
 68#define NODE_MSPEC_BASE(_n)	(MSPEC_BASE + NODE_OFFSET(_n))
 69#define NODE_UNCAC_BASE(_n)	(UNCAC_BASE + NODE_OFFSET(_n))
 70
 71#define TO_NODE(_n, _x)		(NODE_OFFSET(_n)     | ((_x)		   ))
 72#define TO_NODE_CAC(_n, _x)	(NODE_CAC_BASE(_n)   | ((_x) & TO_PHYS_MASK))
 73#define TO_NODE_UNCAC(_n, _x)	(NODE_UNCAC_BASE(_n) | ((_x) & TO_PHYS_MASK))
 74#define TO_NODE_MSPEC(_n, _x)	(NODE_MSPEC_BASE(_n) | ((_x) & TO_PHYS_MASK))
 75#define TO_NODE_HSPEC(_n, _x)	(NODE_HSPEC_BASE(_n) | ((_x) & TO_PHYS_MASK))
 76
 77
 78#define RAW_NODE_SWIN_BASE(nasid, widget)				\
 79	(NODE_IO_BASE(nasid) + (UINT64_CAST(widget) << SWIN_SIZE_BITS))
 80
 81#define WIDGETID_GET(addr)	((unsigned char)((addr >> SWIN_SIZE_BITS) & 0xff))
 82
 83/*
 84 * The following definitions pertain to the IO special address
 85 * space.  They define the location of the big and little windows
 86 * of any given node.
 87 */
 88
 89#define SWIN_SIZE_BITS		24
 90#define SWIN_SIZE		(UINT64_CAST 1 << 24)
 91#define	SWIN_SIZEMASK		(SWIN_SIZE - 1)
 92#define	SWIN_WIDGET_MASK	0xF
 93
 94/*
 95 * Convert smallwindow address to xtalk address.
 96 *
 97 * 'addr' can be physical or virtual address, but will be converted
 98 * to Xtalk address in the range 0 -> SWINZ_SIZEMASK
 99 */
100#define	SWIN_WIDGETADDR(addr)	((addr) & SWIN_SIZEMASK)
101#define	SWIN_WIDGETNUM(addr)	(((addr)  >> SWIN_SIZE_BITS) & SWIN_WIDGET_MASK)
102/*
103 * Verify if addr belongs to small window address on node with "nasid"
104 *
105 *
106 * NOTE: "addr" is expected to be XKPHYS address, and NOT physical
107 * address
108 *
109 *
110 */
111#define	NODE_SWIN_ADDR(nasid, addr)	\
112		(((addr) >= NODE_SWIN_BASE(nasid, 0))  && \
113		 ((addr) <  (NODE_SWIN_BASE(nasid, HUB_NUM_WIDGET) + SWIN_SIZE)\
114		 ))
115
116/*
117 * The following define the major position-independent aliases used
118 * in SN.
119 *	UALIAS -- 256MB in size, reads in the UALIAS result in
120 *			uncached references to the memory of the reader's node.
121 *	CPU_UALIAS -- 128kb in size, the bottom part of UALIAS is flipped
122 *			depending on which CPU does the access to provide
123 *			all CPUs with unique uncached memory at low addresses.
124 *	LBOOT  -- 256MB in size, reads in the LBOOT area result in
125 *			uncached references to the local hub's boot prom and
126 *			other directory-bus connected devices.
127 *	IALIAS -- 8MB in size, reads in the IALIAS result in uncached
128 *			references to the local hub's registers.
129 */
130
131#define UALIAS_BASE		HSPEC_BASE
132#define UALIAS_SIZE		0x10000000	/* 256 Megabytes */
133#define UALIAS_LIMIT		(UALIAS_BASE + UALIAS_SIZE)
134
135/*
136 * The bottom of ualias space is flipped depending on whether you're
137 * processor 0 or 1 within a node.
138 */
139#ifdef CONFIG_SGI_IP27
140#define UALIAS_FLIP_BASE	UALIAS_BASE
141#define UALIAS_FLIP_SIZE	0x20000
142#define UALIAS_FLIP_BIT		0x10000
143#define UALIAS_FLIP_ADDR(_x)	(cputoslice(smp_processor_id()) ? \
144				 (_x) ^ UALIAS_FLIP_BIT : (_x))
145
146#define LBOOT_BASE		(HSPEC_BASE + 0x10000000)
147#define LBOOT_SIZE		0x10000000
148#define LBOOT_LIMIT		(LBOOT_BASE + LBOOT_SIZE)
149#define LBOOT_STRIDE		0		/* IP27 has only one CPU PROM */
150
151#endif
152
153#define	HUB_REGISTER_WIDGET	1
154#define IALIAS_BASE		NODE_SWIN_BASE(0, HUB_REGISTER_WIDGET)
155#define IALIAS_SIZE		0x800000	/* 8 Megabytes */
156#define IS_IALIAS(_a)		(((_a) >= IALIAS_BASE) &&		\
157				 ((_a) < (IALIAS_BASE + IALIAS_SIZE)))
158
159/*
160 * Macro for referring to Hub's RBOOT space
161 */
162
163#ifdef CONFIG_SGI_IP27
164#define RBOOT_SIZE		0x10000000	/* 256 Megabytes */
165#define NODE_RBOOT_BASE(_n)	(NODE_HSPEC_BASE(_n) + 0x30000000)
166#define NODE_RBOOT_LIMIT(_n)	(NODE_RBOOT_BASE(_n) + RBOOT_SIZE)
167
168#endif
169
170/*
171 * Macros for referring the Hub's back door space
172 *
173 *   These macros correctly process addresses in any node's space.
174 *   WARNING: They won't work in assembler.
175 *
176 *   BDDIR_ENTRY_LO returns the address of the low double-word of the dir
177 *                  entry corresponding to a physical (Cac or Uncac) address.
178 *   BDDIR_ENTRY_HI returns the address of the high double-word of the entry.
179 *   BDPRT_ENTRY    returns the address of the double-word protection entry
180 *                  corresponding to the page containing the physical address.
181 *   BDPRT_ENTRY_S  Stores the value into the protection entry.
182 *   BDPRT_ENTRY_L  Load the value from the protection entry.
183 *   BDECC_ENTRY    returns the address of the ECC byte corresponding to a
184 *                  double-word at a specified physical address.
185 *   BDECC_ENTRY_H  returns the address of the two ECC bytes corresponding to a
186 *                  quad-word at a specified physical address.
187 */
188#define NODE_BDOOR_BASE(_n)	(NODE_HSPEC_BASE(_n) + (NODE_ADDRSPACE_SIZE/2))
189
190#define NODE_BDECC_BASE(_n)	(NODE_BDOOR_BASE(_n))
191#define NODE_BDDIR_BASE(_n)	(NODE_BDOOR_BASE(_n) + (NODE_ADDRSPACE_SIZE/4))
192#ifdef CONFIG_SGI_IP27
193#define BDDIR_ENTRY_LO(_pa)	((HSPEC_BASE +				      \
194				  NODE_ADDRSPACE_SIZE * 3 / 4 +		      \
195				  0x200)				    | \
196				 UINT64_CAST(_pa)	 & NASID_MASK	    | \
197				 UINT64_CAST(_pa) >> 2 & BDDIR_UPPER_MASK  | \
198				 UINT64_CAST(_pa) >> 3 & 0x1f << 4)
199
200#define BDDIR_ENTRY_HI(_pa)	((HSPEC_BASE +				      \
201				  NODE_ADDRSPACE_SIZE * 3 / 4 +		      \
202				  0x208)				    | \
203				 UINT64_CAST(_pa)	 & NASID_MASK	    | \
204				 UINT64_CAST(_pa) >> 2 & BDDIR_UPPER_MASK  | \
205				 UINT64_CAST(_pa) >> 3 & 0x1f << 4)
206
207#define BDPRT_ENTRY(_pa, _rgn)	((HSPEC_BASE +				      \
208				  NODE_ADDRSPACE_SIZE * 3 / 4)		    | \
209				 UINT64_CAST(_pa)	 & NASID_MASK	    | \
210				 UINT64_CAST(_pa) >> 2 & BDDIR_UPPER_MASK  | \
211				 (_rgn) << 3)
212#define BDPRT_ENTRY_ADDR(_pa, _rgn) (BDPRT_ENTRY((_pa), (_rgn)))
213#define BDPRT_ENTRY_S(_pa, _rgn, _val) (*(__psunsigned_t *)BDPRT_ENTRY((_pa), (_rgn))=(_val))
214#define BDPRT_ENTRY_L(_pa, _rgn)	(*(__psunsigned_t *)BDPRT_ENTRY((_pa), (_rgn)))
215
216#define BDECC_ENTRY(_pa)	((HSPEC_BASE +				      \
217				  NODE_ADDRSPACE_SIZE / 2)		    | \
218				 UINT64_CAST(_pa)	 & NASID_MASK	    | \
219				 UINT64_CAST(_pa) >> 2 & BDECC_UPPER_MASK  | \
220				 UINT64_CAST(_pa) >> 3 & 3)
221
222/*
223 * Macro to convert a back door directory or protection address into the
224 *   raw physical address of the associated cache line or protection page.
225 */
226#define BDADDR_IS_DIR(_ba)	((UINT64_CAST  (_ba) & 0x200) != 0)
227#define BDADDR_IS_PRT(_ba)	((UINT64_CAST  (_ba) & 0x200) == 0)
228
229#define BDDIR_TO_MEM(_ba)	(UINT64_CAST (_ba) & NASID_MASK            | \
230				 (UINT64_CAST(_ba) & BDDIR_UPPER_MASK)<<2  | \
231				 (UINT64_CAST(_ba) & 0x1f << 4) << 3)
232
233#define BDPRT_TO_MEM(_ba) 	(UINT64_CAST (_ba) & NASID_MASK	    | \
234				 (UINT64_CAST(_ba) & BDDIR_UPPER_MASK)<<2)
235
236#define BDECC_TO_MEM(_ba)	(UINT64_CAST (_ba) & NASID_MASK	    | \
237				 (UINT64_CAST(_ba) & BDECC_UPPER_MASK)<<2  | \
238				 (UINT64_CAST(_ba) & 3) << 3)
239#endif /* CONFIG_SGI_IP27 */
240
241
242/*
243 * The following macros produce the correct base virtual address for
244 * the hub registers.  The LOCAL_HUB_* macros produce the appropriate
245 * address for the local registers.  The REMOTE_HUB_* macro produce
246 * the address for the specified hub's registers.  The intent is
247 * that the appropriate PI, MD, NI, or II register would be substituted
248 * for _x.
249 */
250
251/*
252 * WARNING:
253 *	When certain Hub chip workaround are defined, it's not sufficient
254 *	to dereference the *_HUB_ADDR() macros.  You should instead use
255 *	HUB_L() and HUB_S() if you must deal with pointers to hub registers.
256 *	Otherwise, the recommended approach is to use *_HUB_L() and *_HUB_S().
257 *	They're always safe.
258 */
259#define LOCAL_HUB_ADDR(_x)	(HUBREG_CAST (IALIAS_BASE + (_x)))
260#define REMOTE_HUB_ADDR(_n, _x)	(HUBREG_CAST (NODE_SWIN_BASE(_n, 1) +	\
261					      0x800000 + (_x)))
262#ifdef CONFIG_SGI_IP27
263#define REMOTE_HUB_PI_ADDR(_n, _sn, _x)	(HUBREG_CAST (NODE_SWIN_BASE(_n, 1) +	\
264					      0x800000 + (_x)))
265#endif /* CONFIG_SGI_IP27 */
266
267#ifndef __ASSEMBLY__
268
269#define HUB_L(_a)			*(_a)
270#define	HUB_S(_a, _d)			*(_a) = (_d)
271
272#define LOCAL_HUB_L(_r)			HUB_L(LOCAL_HUB_ADDR(_r))
273#define LOCAL_HUB_S(_r, _d)		HUB_S(LOCAL_HUB_ADDR(_r), (_d))
274#define REMOTE_HUB_L(_n, _r)		HUB_L(REMOTE_HUB_ADDR((_n), (_r)))
275#define REMOTE_HUB_S(_n, _r, _d)	HUB_S(REMOTE_HUB_ADDR((_n), (_r)), (_d))
276#define REMOTE_HUB_PI_L(_n, _sn, _r)	HUB_L(REMOTE_HUB_PI_ADDR((_n), (_sn), (_r)))
277#define REMOTE_HUB_PI_S(_n, _sn, _r, _d) HUB_S(REMOTE_HUB_PI_ADDR((_n), (_sn), (_r)), (_d))
278
279#endif /* !__ASSEMBLY__ */
280
281/*
282 * The following macros are used to get to a hub/bridge register, given
283 * the base of the register space.
284 */
285#define HUB_REG_PTR(_base, _off)	\
286	(HUBREG_CAST((__psunsigned_t)(_base) + (__psunsigned_t)(_off)))
287
288#define HUB_REG_PTR_L(_base, _off)	\
289	HUB_L(HUB_REG_PTR((_base), (_off)))
290
291#define HUB_REG_PTR_S(_base, _off, _data)	\
292	HUB_S(HUB_REG_PTR((_base), (_off)), (_data))
293
294/*
295 * Software structure locations -- permanently fixed
296 *    See diagram in kldir.h
297 */
298
299#define PHYS_RAMBASE		0x0
300#define K0_RAMBASE		PHYS_TO_K0(PHYS_RAMBASE)
301
302#define EX_HANDLER_OFFSET(slice) ((slice) << 16)
303#define EX_HANDLER_ADDR(nasid, slice)					\
304	PHYS_TO_K0(NODE_OFFSET(nasid) | EX_HANDLER_OFFSET(slice))
305#define EX_HANDLER_SIZE		0x0400
306
307#define EX_FRAME_OFFSET(slice)	((slice) << 16 | 0x400)
308#define EX_FRAME_ADDR(nasid, slice)					\
309	PHYS_TO_K0(NODE_OFFSET(nasid) | EX_FRAME_OFFSET(slice))
310#define EX_FRAME_SIZE		0x0c00
311
312#define ARCS_SPB_OFFSET		0x1000
313#define ARCS_SPB_ADDR(nasid)						\
314	PHYS_TO_K0(NODE_OFFSET(nasid) | ARCS_SPB_OFFSET)
315#define ARCS_SPB_SIZE		0x0400
316
317#define KLDIR_OFFSET		0x2000
318#define KLDIR_ADDR(nasid)						\
319	TO_NODE_UNCAC((nasid), KLDIR_OFFSET)
320#define KLDIR_SIZE		0x0400
321
322
323/*
324 * Software structure locations -- indirected through KLDIR
325 *    See diagram in kldir.h
326 *
327 * Important:	All low memory structures must only be accessed
328 *		uncached, except for the symmon stacks.
329 */
330
331#define KLI_LAUNCH		0		/* Dir. entries */
332#define KLI_KLCONFIG		1
333#define	KLI_NMI			2
334#define KLI_GDA			3
335#define KLI_FREEMEM		4
336#define	KLI_SYMMON_STK		5
337#define KLI_PI_ERROR		6
338#define KLI_KERN_VARS		7
339#define	KLI_KERN_XP		8
340#define	KLI_KERN_PARTID		9
341
342#ifndef __ASSEMBLY__
343
344#define KLD_BASE(nasid)		((kldir_ent_t *) KLDIR_ADDR(nasid))
345#define KLD_LAUNCH(nasid)	(KLD_BASE(nasid) + KLI_LAUNCH)
346#define KLD_NMI(nasid)		(KLD_BASE(nasid) + KLI_NMI)
347#define KLD_KLCONFIG(nasid)	(KLD_BASE(nasid) + KLI_KLCONFIG)
348#define KLD_PI_ERROR(nasid)	(KLD_BASE(nasid) + KLI_PI_ERROR)
349#define KLD_GDA(nasid)		(KLD_BASE(nasid) + KLI_GDA)
350#define KLD_SYMMON_STK(nasid)	(KLD_BASE(nasid) + KLI_SYMMON_STK)
351#define KLD_FREEMEM(nasid)	(KLD_BASE(nasid) + KLI_FREEMEM)
352#define KLD_KERN_VARS(nasid)	(KLD_BASE(nasid) + KLI_KERN_VARS)
353#define	KLD_KERN_XP(nasid)	(KLD_BASE(nasid) + KLI_KERN_XP)
354#define	KLD_KERN_PARTID(nasid)	(KLD_BASE(nasid) + KLI_KERN_PARTID)
355
356#define LAUNCH_OFFSET(nasid, slice)					\
357	(KLD_LAUNCH(nasid)->offset +					\
358	 KLD_LAUNCH(nasid)->stride * (slice))
359#define LAUNCH_ADDR(nasid, slice)					\
360	TO_NODE_UNCAC((nasid), LAUNCH_OFFSET(nasid, slice))
361#define LAUNCH_SIZE(nasid)	KLD_LAUNCH(nasid)->size
362
363#define SN_NMI_OFFSET(nasid, slice)					\
364	(KLD_NMI(nasid)->offset +					\
365	 KLD_NMI(nasid)->stride * (slice))
366#define NMI_ADDR(nasid, slice)						\
367	TO_NODE_UNCAC((nasid), SN_NMI_OFFSET(nasid, slice))
368#define NMI_SIZE(nasid)	KLD_NMI(nasid)->size
369
370#define KLCONFIG_OFFSET(nasid)	KLD_KLCONFIG(nasid)->offset
371#define KLCONFIG_ADDR(nasid)						\
372	TO_NODE_UNCAC((nasid), KLCONFIG_OFFSET(nasid))
373#define KLCONFIG_SIZE(nasid)	KLD_KLCONFIG(nasid)->size
374
375#define GDA_ADDR(nasid)		KLD_GDA(nasid)->pointer
376#define GDA_SIZE(nasid)		KLD_GDA(nasid)->size
377
378#define SYMMON_STK_OFFSET(nasid, slice)					\
379	(KLD_SYMMON_STK(nasid)->offset +				\
380	 KLD_SYMMON_STK(nasid)->stride * (slice))
381#define SYMMON_STK_STRIDE(nasid)	KLD_SYMMON_STK(nasid)->stride
382
383#define SYMMON_STK_ADDR(nasid, slice)					\
384	TO_NODE_CAC((nasid), SYMMON_STK_OFFSET(nasid, slice))
385
386#define SYMMON_STK_SIZE(nasid)	KLD_SYMMON_STK(nasid)->stride
387
388#define SYMMON_STK_END(nasid)	(SYMMON_STK_ADDR(nasid, 0) + KLD_SYMMON_STK(nasid)->size)
389
390/* loading symmon 4k below UNIX. the arcs loader needs the topaddr for a
391 * relocatable program
392 */
393#define	UNIX_DEBUG_LOADADDR	0x300000
394#define	SYMMON_LOADADDR(nasid)						\
395	TO_NODE(nasid, PHYS_TO_K0(UNIX_DEBUG_LOADADDR - 0x1000))
396
397#define FREEMEM_OFFSET(nasid)	KLD_FREEMEM(nasid)->offset
398#define FREEMEM_ADDR(nasid)	SYMMON_STK_END(nasid)
399/*
400 * XXX
401 * Fix this. FREEMEM_ADDR should be aware of if symmon is loaded.
402 * Also, it should take into account what prom thinks to be a safe
403 * address
404	PHYS_TO_K0(NODE_OFFSET(nasid) + FREEMEM_OFFSET(nasid))
405 */
406#define FREEMEM_SIZE(nasid)	KLD_FREEMEM(nasid)->size
407
408#define PI_ERROR_OFFSET(nasid)	KLD_PI_ERROR(nasid)->offset
409#define PI_ERROR_ADDR(nasid)						\
410	TO_NODE_UNCAC((nasid), PI_ERROR_OFFSET(nasid))
411#define PI_ERROR_SIZE(nasid)	KLD_PI_ERROR(nasid)->size
412
413#define NODE_OFFSET_TO_K0(_nasid, _off)					\
414	PHYS_TO_K0((NODE_OFFSET(_nasid) + (_off)) | CAC_BASE)
415#define NODE_OFFSET_TO_K1(_nasid, _off)					\
416	TO_UNCAC((NODE_OFFSET(_nasid) + (_off)) | UNCAC_BASE)
417#define K0_TO_NODE_OFFSET(_k0addr)					\
418	((__psunsigned_t)(_k0addr) & NODE_ADDRSPACE_MASK)
419
420#define KERN_VARS_ADDR(nasid)	KLD_KERN_VARS(nasid)->pointer
421#define KERN_VARS_SIZE(nasid)	KLD_KERN_VARS(nasid)->size
422
423#define	KERN_XP_ADDR(nasid)	KLD_KERN_XP(nasid)->pointer
424#define	KERN_XP_SIZE(nasid)	KLD_KERN_XP(nasid)->size
425
426#define GPDA_ADDR(nasid)	TO_NODE_CAC(nasid, GPDA_OFFSET)
427
428#endif /* !__ASSEMBLY__ */
429
430
431#endif /* _ASM_SN_ADDRS_H */