blob: 3f7564dc0aa9bf052b6fee3a20791d4ac7ebb811 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_IA64_SN_SN_SAL_H
2#define _ASM_IA64_SN_SN_SAL_H
3
4/*
5 * System Abstraction Layer definitions for IA64
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 *
Russ Anderson93a07d02005-04-25 13:19:52 -070011 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
14
15#include <linux/config.h>
16#include <asm/sal.h>
17#include <asm/sn/sn_cpuid.h>
18#include <asm/sn/arch.h>
19#include <asm/sn/geo.h>
20#include <asm/sn/nodepda.h>
21#include <asm/sn/shub_mmr.h>
22
23// SGI Specific Calls
24#define SN_SAL_POD_MODE 0x02000001
25#define SN_SAL_SYSTEM_RESET 0x02000002
26#define SN_SAL_PROBE 0x02000003
27#define SN_SAL_GET_MASTER_NASID 0x02000004
28#define SN_SAL_GET_KLCONFIG_ADDR 0x02000005
29#define SN_SAL_LOG_CE 0x02000006
30#define SN_SAL_REGISTER_CE 0x02000007
31#define SN_SAL_GET_PARTITION_ADDR 0x02000009
32#define SN_SAL_XP_ADDR_REGION 0x0200000f
33#define SN_SAL_NO_FAULT_ZONE_VIRTUAL 0x02000010
34#define SN_SAL_NO_FAULT_ZONE_PHYSICAL 0x02000011
35#define SN_SAL_PRINT_ERROR 0x02000012
36#define SN_SAL_SET_ERROR_HANDLING_FEATURES 0x0200001a // reentrant
37#define SN_SAL_GET_FIT_COMPT 0x0200001b // reentrant
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define SN_SAL_GET_SAPIC_INFO 0x0200001d
Jack Steinerbf1cf98f2005-04-25 11:42:39 -070039#define SN_SAL_GET_SN_INFO 0x0200001e
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define SN_SAL_CONSOLE_PUTC 0x02000021
41#define SN_SAL_CONSOLE_GETC 0x02000022
42#define SN_SAL_CONSOLE_PUTS 0x02000023
43#define SN_SAL_CONSOLE_GETS 0x02000024
44#define SN_SAL_CONSOLE_GETS_TIMEOUT 0x02000025
45#define SN_SAL_CONSOLE_POLL 0x02000026
46#define SN_SAL_CONSOLE_INTR 0x02000027
47#define SN_SAL_CONSOLE_PUTB 0x02000028
48#define SN_SAL_CONSOLE_XMIT_CHARS 0x0200002a
49#define SN_SAL_CONSOLE_READC 0x0200002b
Bruce Losure25732ad2005-09-02 15:16:35 -050050#define SN_SAL_SYSCTL_OP 0x02000030
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define SN_SAL_SYSCTL_MODID_GET 0x02000031
52#define SN_SAL_SYSCTL_GET 0x02000032
53#define SN_SAL_SYSCTL_IOBRICK_MODULE_GET 0x02000033
54#define SN_SAL_SYSCTL_IO_PORTSPEED_GET 0x02000035
55#define SN_SAL_SYSCTL_SLAB_GET 0x02000036
56#define SN_SAL_BUS_CONFIG 0x02000037
57#define SN_SAL_SYS_SERIAL_GET 0x02000038
58#define SN_SAL_PARTITION_SERIAL_GET 0x02000039
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define SN_SAL_SYSTEM_POWER_DOWN 0x0200003b
60#define SN_SAL_GET_MASTER_BASEIO_NASID 0x0200003c
61#define SN_SAL_COHERENCE 0x0200003d
62#define SN_SAL_MEMPROTECT 0x0200003e
63#define SN_SAL_SYSCTL_FRU_CAPTURE 0x0200003f
64
65#define SN_SAL_SYSCTL_IOBRICK_PCI_OP 0x02000042 // reentrant
66#define SN_SAL_IROUTER_OP 0x02000043
Greg Howard67639de2005-04-25 13:28:52 -070067#define SN_SAL_SYSCTL_EVENT 0x02000044
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define SN_SAL_IOIF_INTERRUPT 0x0200004a
69#define SN_SAL_HWPERF_OP 0x02000050 // lock
70#define SN_SAL_IOIF_ERROR_INTERRUPT 0x02000051
Mark Maule61b9cf72005-09-23 12:31:53 -050071#define SN_SAL_IOIF_PCI_SAFE 0x02000052
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#define SN_SAL_IOIF_SLOT_ENABLE 0x02000053
73#define SN_SAL_IOIF_SLOT_DISABLE 0x02000054
74#define SN_SAL_IOIF_GET_HUBDEV_INFO 0x02000055
75#define SN_SAL_IOIF_GET_PCIBUS_INFO 0x02000056
76#define SN_SAL_IOIF_GET_PCIDEV_INFO 0x02000057
77#define SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST 0x02000058
78
79#define SN_SAL_HUB_ERROR_INTERRUPT 0x02000060
Russ Anderson93a07d02005-04-25 13:19:52 -070080#define SN_SAL_BTE_RECOVER 0x02000061
Mark Goodwinecc3c302005-08-16 00:50:00 -070081#define SN_SAL_RESERVED_DO_NOT_USE 0x02000062
82#define SN_SAL_IOIF_GET_PCI_TOPOLOGY 0x02000064
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Jack Steinera1cddb82005-08-31 08:05:00 -070084#define SN_SAL_GET_PROM_FEATURE_SET 0x02000065
85#define SN_SAL_SET_OS_FEATURE_SET 0x02000066
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087/*
88 * Service-specific constants
89 */
90
91/* Console interrupt manipulation */
92 /* action codes */
93#define SAL_CONSOLE_INTR_OFF 0 /* turn the interrupt off */
94#define SAL_CONSOLE_INTR_ON 1 /* turn the interrupt on */
95#define SAL_CONSOLE_INTR_STATUS 2 /* retrieve the interrupt status */
96 /* interrupt specification & status return codes */
97#define SAL_CONSOLE_INTR_XMIT 1 /* output interrupt */
98#define SAL_CONSOLE_INTR_RECV 2 /* input interrupt */
99
100/* interrupt handling */
101#define SAL_INTR_ALLOC 1
102#define SAL_INTR_FREE 2
103
104/*
Bruce Losure25732ad2005-09-02 15:16:35 -0500105 * operations available on the generic SN_SAL_SYSCTL_OP
106 * runtime service
107 */
108#define SAL_SYSCTL_OP_IOBOARD 0x0001 /* retrieve board type */
109#define SAL_SYSCTL_OP_TIO_JLCK_RST 0x0002 /* issue TIO clock reset */
110
111/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 * IRouter (i.e. generalized system controller) operations
113 */
114#define SAL_IROUTER_OPEN 0 /* open a subchannel */
115#define SAL_IROUTER_CLOSE 1 /* close a subchannel */
116#define SAL_IROUTER_SEND 2 /* send part of an IRouter packet */
117#define SAL_IROUTER_RECV 3 /* receive part of an IRouter packet */
118#define SAL_IROUTER_INTR_STATUS 4 /* check the interrupt status for
119 * an open subchannel
120 */
121#define SAL_IROUTER_INTR_ON 5 /* enable an interrupt */
122#define SAL_IROUTER_INTR_OFF 6 /* disable an interrupt */
123#define SAL_IROUTER_INIT 7 /* initialize IRouter driver */
124
125/* IRouter interrupt mask bits */
126#define SAL_IROUTER_INTR_XMIT SAL_CONSOLE_INTR_XMIT
127#define SAL_IROUTER_INTR_RECV SAL_CONSOLE_INTR_RECV
128
Russ Anderson6872ec52005-05-16 15:30:00 -0700129/*
130 * Error Handling Features
131 */
Jack Steinera1cddb82005-08-31 08:05:00 -0700132#define SAL_ERR_FEAT_MCA_SLV_TO_OS_INIT_SLV 0x1 // obsolete
133#define SAL_ERR_FEAT_LOG_SBES 0x2 // obsolete
Russ Anderson6872ec52005-05-16 15:30:00 -0700134#define SAL_ERR_FEAT_MFR_OVERRIDE 0x4
135#define SAL_ERR_FEAT_SBE_THRESHOLD 0xffff0000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137/*
138 * SAL Error Codes
139 */
140#define SALRET_MORE_PASSES 1
141#define SALRET_OK 0
142#define SALRET_NOT_IMPLEMENTED (-1)
143#define SALRET_INVALID_ARG (-2)
144#define SALRET_ERROR (-3)
145
Jack Steiner71a5d022005-05-10 08:01:00 -0700146#define SN_SAL_FAKE_PROM 0x02009999
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148/**
Prarit Bhargava283c7f62005-07-06 15:29:13 -0700149 * sn_sal_revision - get the SGI SAL revision number
150 *
151 * The SGI PROM stores its version in the sal_[ab]_rev_(major|minor).
152 * This routine simply extracts the major and minor values and
153 * presents them in a u32 format.
154 *
155 * For example, version 4.05 would be represented at 0x0405.
156 */
157static inline u32
158sn_sal_rev(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
160 struct ia64_sal_systab *systab = efi.sal_systab;
161
Prarit Bhargava283c7f62005-07-06 15:29:13 -0700162 return (u32)(systab->sal_b_rev_major << 8 | systab->sal_b_rev_minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 * Returns the master console nasid, if the call fails, return an illegal
167 * value.
168 */
169static inline u64
170ia64_sn_get_console_nasid(void)
171{
172 struct ia64_sal_retval ret_stuff;
173
174 ret_stuff.status = 0;
175 ret_stuff.v0 = 0;
176 ret_stuff.v1 = 0;
177 ret_stuff.v2 = 0;
178 SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_NASID, 0, 0, 0, 0, 0, 0, 0);
179
180 if (ret_stuff.status < 0)
181 return ret_stuff.status;
182
183 /* Master console nasid is in 'v0' */
184 return ret_stuff.v0;
185}
186
187/*
188 * Returns the master baseio nasid, if the call fails, return an illegal
189 * value.
190 */
191static inline u64
192ia64_sn_get_master_baseio_nasid(void)
193{
194 struct ia64_sal_retval ret_stuff;
195
196 ret_stuff.status = 0;
197 ret_stuff.v0 = 0;
198 ret_stuff.v1 = 0;
199 ret_stuff.v2 = 0;
200 SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_BASEIO_NASID, 0, 0, 0, 0, 0, 0, 0);
201
202 if (ret_stuff.status < 0)
203 return ret_stuff.status;
204
205 /* Master baseio nasid is in 'v0' */
206 return ret_stuff.v0;
207}
208
Jack Steiner24ee0a62005-09-12 12:15:43 -0500209static inline void *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210ia64_sn_get_klconfig_addr(nasid_t nasid)
211{
212 struct ia64_sal_retval ret_stuff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 ret_stuff.status = 0;
215 ret_stuff.v0 = 0;
216 ret_stuff.v1 = 0;
217 ret_stuff.v2 = 0;
218 SAL_CALL(ret_stuff, SN_SAL_GET_KLCONFIG_ADDR, (u64)nasid, 0, 0, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return ret_stuff.v0 ? __va(ret_stuff.v0) : NULL;
220}
221
222/*
223 * Returns the next console character.
224 */
225static inline u64
226ia64_sn_console_getc(int *ch)
227{
228 struct ia64_sal_retval ret_stuff;
229
230 ret_stuff.status = 0;
231 ret_stuff.v0 = 0;
232 ret_stuff.v1 = 0;
233 ret_stuff.v2 = 0;
234 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_GETC, 0, 0, 0, 0, 0, 0, 0);
235
236 /* character is in 'v0' */
237 *ch = (int)ret_stuff.v0;
238
239 return ret_stuff.status;
240}
241
242/*
243 * Read a character from the SAL console device, after a previous interrupt
244 * or poll operation has given us to know that a character is available
245 * to be read.
246 */
247static inline u64
248ia64_sn_console_readc(void)
249{
250 struct ia64_sal_retval ret_stuff;
251
252 ret_stuff.status = 0;
253 ret_stuff.v0 = 0;
254 ret_stuff.v1 = 0;
255 ret_stuff.v2 = 0;
256 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_READC, 0, 0, 0, 0, 0, 0, 0);
257
258 /* character is in 'v0' */
259 return ret_stuff.v0;
260}
261
262/*
263 * Sends the given character to the console.
264 */
265static inline u64
266ia64_sn_console_putc(char ch)
267{
268 struct ia64_sal_retval ret_stuff;
269
270 ret_stuff.status = 0;
271 ret_stuff.v0 = 0;
272 ret_stuff.v1 = 0;
273 ret_stuff.v2 = 0;
274 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_PUTC, (uint64_t)ch, 0, 0, 0, 0, 0, 0);
275
276 return ret_stuff.status;
277}
278
279/*
280 * Sends the given buffer to the console.
281 */
282static inline u64
283ia64_sn_console_putb(const char *buf, int len)
284{
285 struct ia64_sal_retval ret_stuff;
286
287 ret_stuff.status = 0;
288 ret_stuff.v0 = 0;
289 ret_stuff.v1 = 0;
290 ret_stuff.v2 = 0;
291 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_PUTB, (uint64_t)buf, (uint64_t)len, 0, 0, 0, 0, 0);
292
293 if ( ret_stuff.status == 0 ) {
294 return ret_stuff.v0;
295 }
296 return (u64)0;
297}
298
299/*
300 * Print a platform error record
301 */
302static inline u64
303ia64_sn_plat_specific_err_print(int (*hook)(const char*, ...), char *rec)
304{
305 struct ia64_sal_retval ret_stuff;
306
307 ret_stuff.status = 0;
308 ret_stuff.v0 = 0;
309 ret_stuff.v1 = 0;
310 ret_stuff.v2 = 0;
311 SAL_CALL_REENTRANT(ret_stuff, SN_SAL_PRINT_ERROR, (uint64_t)hook, (uint64_t)rec, 0, 0, 0, 0, 0);
312
313 return ret_stuff.status;
314}
315
316/*
317 * Check for Platform errors
318 */
319static inline u64
320ia64_sn_plat_cpei_handler(void)
321{
322 struct ia64_sal_retval ret_stuff;
323
324 ret_stuff.status = 0;
325 ret_stuff.v0 = 0;
326 ret_stuff.v1 = 0;
327 ret_stuff.v2 = 0;
328 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_LOG_CE, 0, 0, 0, 0, 0, 0, 0);
329
330 return ret_stuff.status;
331}
332
333/*
Jack Steinera1cddb82005-08-31 08:05:00 -0700334 * Set Error Handling Features (Obsolete)
Russ Anderson6872ec52005-05-16 15:30:00 -0700335 */
336static inline u64
337ia64_sn_plat_set_error_handling_features(void)
338{
339 struct ia64_sal_retval ret_stuff;
340
341 ret_stuff.status = 0;
342 ret_stuff.v0 = 0;
343 ret_stuff.v1 = 0;
344 ret_stuff.v2 = 0;
345 SAL_CALL_REENTRANT(ret_stuff, SN_SAL_SET_ERROR_HANDLING_FEATURES,
346 (SAL_ERR_FEAT_MCA_SLV_TO_OS_INIT_SLV | SAL_ERR_FEAT_LOG_SBES),
347 0, 0, 0, 0, 0, 0);
348
349 return ret_stuff.status;
350}
351
352/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 * Checks for console input.
354 */
355static inline u64
356ia64_sn_console_check(int *result)
357{
358 struct ia64_sal_retval ret_stuff;
359
360 ret_stuff.status = 0;
361 ret_stuff.v0 = 0;
362 ret_stuff.v1 = 0;
363 ret_stuff.v2 = 0;
364 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_POLL, 0, 0, 0, 0, 0, 0, 0);
365
366 /* result is in 'v0' */
367 *result = (int)ret_stuff.v0;
368
369 return ret_stuff.status;
370}
371
372/*
373 * Checks console interrupt status
374 */
375static inline u64
376ia64_sn_console_intr_status(void)
377{
378 struct ia64_sal_retval ret_stuff;
379
380 ret_stuff.status = 0;
381 ret_stuff.v0 = 0;
382 ret_stuff.v1 = 0;
383 ret_stuff.v2 = 0;
384 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_INTR,
385 0, SAL_CONSOLE_INTR_STATUS,
386 0, 0, 0, 0, 0);
387
388 if (ret_stuff.status == 0) {
389 return ret_stuff.v0;
390 }
391
392 return 0;
393}
394
395/*
396 * Enable an interrupt on the SAL console device.
397 */
398static inline void
399ia64_sn_console_intr_enable(uint64_t intr)
400{
401 struct ia64_sal_retval ret_stuff;
402
403 ret_stuff.status = 0;
404 ret_stuff.v0 = 0;
405 ret_stuff.v1 = 0;
406 ret_stuff.v2 = 0;
407 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_INTR,
408 intr, SAL_CONSOLE_INTR_ON,
409 0, 0, 0, 0, 0);
410}
411
412/*
413 * Disable an interrupt on the SAL console device.
414 */
415static inline void
416ia64_sn_console_intr_disable(uint64_t intr)
417{
418 struct ia64_sal_retval ret_stuff;
419
420 ret_stuff.status = 0;
421 ret_stuff.v0 = 0;
422 ret_stuff.v1 = 0;
423 ret_stuff.v2 = 0;
424 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_INTR,
425 intr, SAL_CONSOLE_INTR_OFF,
426 0, 0, 0, 0, 0);
427}
428
429/*
430 * Sends a character buffer to the console asynchronously.
431 */
432static inline u64
433ia64_sn_console_xmit_chars(char *buf, int len)
434{
435 struct ia64_sal_retval ret_stuff;
436
437 ret_stuff.status = 0;
438 ret_stuff.v0 = 0;
439 ret_stuff.v1 = 0;
440 ret_stuff.v2 = 0;
441 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_XMIT_CHARS,
442 (uint64_t)buf, (uint64_t)len,
443 0, 0, 0, 0, 0);
444
445 if (ret_stuff.status == 0) {
446 return ret_stuff.v0;
447 }
448
449 return 0;
450}
451
452/*
453 * Returns the iobrick module Id
454 */
455static inline u64
456ia64_sn_sysctl_iobrick_module_get(nasid_t nasid, int *result)
457{
458 struct ia64_sal_retval ret_stuff;
459
460 ret_stuff.status = 0;
461 ret_stuff.v0 = 0;
462 ret_stuff.v1 = 0;
463 ret_stuff.v2 = 0;
464 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_SYSCTL_IOBRICK_MODULE_GET, nasid, 0, 0, 0, 0, 0, 0);
465
466 /* result is in 'v0' */
467 *result = (int)ret_stuff.v0;
468
469 return ret_stuff.status;
470}
471
472/**
473 * ia64_sn_pod_mode - call the SN_SAL_POD_MODE function
474 *
475 * SN_SAL_POD_MODE actually takes an argument, but it's always
476 * 0 when we call it from the kernel, so we don't have to expose
477 * it to the caller.
478 */
479static inline u64
480ia64_sn_pod_mode(void)
481{
482 struct ia64_sal_retval isrv;
Russ Anderson8eac3752005-05-16 15:19:00 -0700483 SAL_CALL_REENTRANT(isrv, SN_SAL_POD_MODE, 0, 0, 0, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 if (isrv.status)
485 return 0;
486 return isrv.v0;
487}
488
489/**
490 * ia64_sn_probe_mem - read from memory safely
491 * @addr: address to probe
492 * @size: number bytes to read (1,2,4,8)
493 * @data_ptr: address to store value read by probe (-1 returned if probe fails)
494 *
495 * Call into the SAL to do a memory read. If the read generates a machine
496 * check, this routine will recover gracefully and return -1 to the caller.
497 * @addr is usually a kernel virtual address in uncached space (i.e. the
498 * address starts with 0xc), but if called in physical mode, @addr should
499 * be a physical address.
500 *
501 * Return values:
502 * 0 - probe successful
503 * 1 - probe failed (generated MCA)
504 * 2 - Bad arg
505 * <0 - PAL error
506 */
507static inline u64
508ia64_sn_probe_mem(long addr, long size, void *data_ptr)
509{
510 struct ia64_sal_retval isrv;
511
512 SAL_CALL(isrv, SN_SAL_PROBE, addr, size, 0, 0, 0, 0, 0);
513
514 if (data_ptr) {
515 switch (size) {
516 case 1:
517 *((u8*)data_ptr) = (u8)isrv.v0;
518 break;
519 case 2:
520 *((u16*)data_ptr) = (u16)isrv.v0;
521 break;
522 case 4:
523 *((u32*)data_ptr) = (u32)isrv.v0;
524 break;
525 case 8:
526 *((u64*)data_ptr) = (u64)isrv.v0;
527 break;
528 default:
529 isrv.status = 2;
530 }
531 }
532 return isrv.status;
533}
534
535/*
536 * Retrieve the system serial number as an ASCII string.
537 */
538static inline u64
539ia64_sn_sys_serial_get(char *buf)
540{
541 struct ia64_sal_retval ret_stuff;
542 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_SYS_SERIAL_GET, buf, 0, 0, 0, 0, 0, 0);
543 return ret_stuff.status;
544}
545
546extern char sn_system_serial_number_string[];
547extern u64 sn_partition_serial_number;
548
549static inline char *
550sn_system_serial_number(void) {
551 if (sn_system_serial_number_string[0]) {
552 return(sn_system_serial_number_string);
553 } else {
554 ia64_sn_sys_serial_get(sn_system_serial_number_string);
555 return(sn_system_serial_number_string);
556 }
557}
558
559
560/*
561 * Returns a unique id number for this system and partition (suitable for
562 * use with license managers), based in part on the system serial number.
563 */
564static inline u64
565ia64_sn_partition_serial_get(void)
566{
567 struct ia64_sal_retval ret_stuff;
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700568 ia64_sal_oemcall_reentrant(&ret_stuff, SN_SAL_PARTITION_SERIAL_GET, 0,
569 0, 0, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 if (ret_stuff.status != 0)
571 return 0;
572 return ret_stuff.v0;
573}
574
575static inline u64
576sn_partition_serial_number_val(void) {
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700577 if (unlikely(sn_partition_serial_number == 0)) {
578 sn_partition_serial_number = ia64_sn_partition_serial_get();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700580 return sn_partition_serial_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581}
582
583/*
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700584 * Returns the physical address of the partition's reserved page through
585 * an iterative number of calls.
586 *
587 * On first call, 'cookie' and 'len' should be set to 0, and 'addr'
588 * set to the nasid of the partition whose reserved page's address is
589 * being sought.
590 * On subsequent calls, pass the values, that were passed back on the
591 * previous call.
592 *
593 * While the return status equals SALRET_MORE_PASSES, keep calling
594 * this function after first copying 'len' bytes starting at 'addr'
595 * into 'buf'. Once the return status equals SALRET_OK, 'addr' will
596 * be the physical address of the partition's reserved page. If the
597 * return status equals neither of these, an error as occurred.
598 */
599static inline s64
600sn_partition_reserved_page_pa(u64 buf, u64 *cookie, u64 *addr, u64 *len)
601{
602 struct ia64_sal_retval rv;
603 ia64_sal_oemcall_reentrant(&rv, SN_SAL_GET_PARTITION_ADDR, *cookie,
604 *addr, buf, *len, 0, 0, 0);
605 *cookie = rv.v0;
606 *addr = rv.v1;
607 *len = rv.v2;
608 return rv.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609}
610
611/*
612 * Register or unregister a physical address range being referenced across
613 * a partition boundary for which certain SAL errors should be scanned for,
614 * cleaned up and ignored. This is of value for kernel partitioning code only.
615 * Values for the operation argument:
616 * 1 = register this address range with SAL
617 * 0 = unregister this address range with SAL
618 *
619 * SAL maintains a reference count on an address range in case it is registered
620 * multiple times.
621 *
622 * On success, returns the reference count of the address range after the SAL
623 * call has performed the current registration/unregistration. Returns a
624 * negative value if an error occurred.
625 */
626static inline int
627sn_register_xp_addr_region(u64 paddr, u64 len, int operation)
628{
629 struct ia64_sal_retval ret_stuff;
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700630 ia64_sal_oemcall(&ret_stuff, SN_SAL_XP_ADDR_REGION, paddr, len,
631 (u64)operation, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 return ret_stuff.status;
633}
634
635/*
636 * Register or unregister an instruction range for which SAL errors should
637 * be ignored. If an error occurs while in the registered range, SAL jumps
638 * to return_addr after ignoring the error. Values for the operation argument:
639 * 1 = register this instruction range with SAL
640 * 0 = unregister this instruction range with SAL
641 *
642 * Returns 0 on success, or a negative value if an error occurred.
643 */
644static inline int
645sn_register_nofault_code(u64 start_addr, u64 end_addr, u64 return_addr,
646 int virtual, int operation)
647{
648 struct ia64_sal_retval ret_stuff;
649 u64 call;
650 if (virtual) {
651 call = SN_SAL_NO_FAULT_ZONE_VIRTUAL;
652 } else {
653 call = SN_SAL_NO_FAULT_ZONE_PHYSICAL;
654 }
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700655 ia64_sal_oemcall(&ret_stuff, call, start_addr, end_addr, return_addr,
656 (u64)1, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 return ret_stuff.status;
658}
659
660/*
661 * Change or query the coherence domain for this partition. Each cpu-based
662 * nasid is represented by a bit in an array of 64-bit words:
663 * 0 = not in this partition's coherency domain
664 * 1 = in this partition's coherency domain
665 *
666 * It is not possible for the local system's nasids to be removed from
667 * the coherency domain. Purpose of the domain arguments:
668 * new_domain = set the coherence domain to the given nasids
669 * old_domain = return the current coherence domain
670 *
671 * Returns 0 on success, or a negative value if an error occurred.
672 */
673static inline int
674sn_change_coherence(u64 *new_domain, u64 *old_domain)
675{
676 struct ia64_sal_retval ret_stuff;
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700677 ia64_sal_oemcall(&ret_stuff, SN_SAL_COHERENCE, (u64)new_domain,
678 (u64)old_domain, 0, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 return ret_stuff.status;
680}
681
682/*
683 * Change memory access protections for a physical address range.
684 * nasid_array is not used on Altix, but may be in future architectures.
685 * Available memory protection access classes are defined after the function.
686 */
687static inline int
688sn_change_memprotect(u64 paddr, u64 len, u64 perms, u64 *nasid_array)
689{
690 struct ia64_sal_retval ret_stuff;
691 int cnodeid;
692 unsigned long irq_flags;
693
694 cnodeid = nasid_to_cnodeid(get_node_number(paddr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 local_irq_save(irq_flags);
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700696 ia64_sal_oemcall_nolock(&ret_stuff, SN_SAL_MEMPROTECT, paddr, len,
697 (u64)nasid_array, perms, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 local_irq_restore(irq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 return ret_stuff.status;
700}
701#define SN_MEMPROT_ACCESS_CLASS_0 0x14a080
702#define SN_MEMPROT_ACCESS_CLASS_1 0x2520c2
703#define SN_MEMPROT_ACCESS_CLASS_2 0x14a1ca
704#define SN_MEMPROT_ACCESS_CLASS_3 0x14a290
705#define SN_MEMPROT_ACCESS_CLASS_6 0x084080
706#define SN_MEMPROT_ACCESS_CLASS_7 0x021080
707
708/*
709 * Turns off system power.
710 */
711static inline void
712ia64_sn_power_down(void)
713{
714 struct ia64_sal_retval ret_stuff;
715 SAL_CALL(ret_stuff, SN_SAL_SYSTEM_POWER_DOWN, 0, 0, 0, 0, 0, 0, 0);
Jack Steiner68b97532005-08-11 10:28:00 -0700716 while(1)
717 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 /* never returns */
719}
720
721/**
722 * ia64_sn_fru_capture - tell the system controller to capture hw state
723 *
724 * This routine will call the SAL which will tell the system controller(s)
725 * to capture hw mmr information from each SHub in the system.
726 */
727static inline u64
728ia64_sn_fru_capture(void)
729{
730 struct ia64_sal_retval isrv;
731 SAL_CALL(isrv, SN_SAL_SYSCTL_FRU_CAPTURE, 0, 0, 0, 0, 0, 0, 0);
732 if (isrv.status)
733 return 0;
734 return isrv.v0;
735}
736
737/*
738 * Performs an operation on a PCI bus or slot -- power up, power down
739 * or reset.
740 */
741static inline u64
742ia64_sn_sysctl_iobrick_pci_op(nasid_t n, u64 connection_type,
743 u64 bus, char slot,
744 u64 action)
745{
746 struct ia64_sal_retval rv = {0, 0, 0, 0};
747
748 SAL_CALL_NOLOCK(rv, SN_SAL_SYSCTL_IOBRICK_PCI_OP, connection_type, n, action,
749 bus, (u64) slot, 0, 0);
750 if (rv.status)
751 return rv.v0;
752 return 0;
753}
754
755
756/*
757 * Open a subchannel for sending arbitrary data to the system
758 * controller network via the system controller device associated with
759 * 'nasid'. Return the subchannel number or a negative error code.
760 */
761static inline int
762ia64_sn_irtr_open(nasid_t nasid)
763{
764 struct ia64_sal_retval rv;
765 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_OPEN, nasid,
766 0, 0, 0, 0, 0);
767 return (int) rv.v0;
768}
769
770/*
771 * Close system controller subchannel 'subch' previously opened on 'nasid'.
772 */
773static inline int
774ia64_sn_irtr_close(nasid_t nasid, int subch)
775{
776 struct ia64_sal_retval rv;
777 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_CLOSE,
778 (u64) nasid, (u64) subch, 0, 0, 0, 0);
779 return (int) rv.status;
780}
781
782/*
783 * Read data from system controller associated with 'nasid' on
784 * subchannel 'subch'. The buffer to be filled is pointed to by
785 * 'buf', and its capacity is in the integer pointed to by 'len'. The
786 * referent of 'len' is set to the number of bytes read by the SAL
787 * call. The return value is either SALRET_OK (for bytes read) or
788 * SALRET_ERROR (for error or "no data available").
789 */
790static inline int
791ia64_sn_irtr_recv(nasid_t nasid, int subch, char *buf, int *len)
792{
793 struct ia64_sal_retval rv;
794 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_RECV,
795 (u64) nasid, (u64) subch, (u64) buf, (u64) len,
796 0, 0);
797 return (int) rv.status;
798}
799
800/*
801 * Write data to the system controller network via the system
802 * controller associated with 'nasid' on suchannel 'subch'. The
803 * buffer to be written out is pointed to by 'buf', and 'len' is the
804 * number of bytes to be written. The return value is either the
805 * number of bytes written (which could be zero) or a negative error
806 * code.
807 */
808static inline int
809ia64_sn_irtr_send(nasid_t nasid, int subch, char *buf, int len)
810{
811 struct ia64_sal_retval rv;
812 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_SEND,
813 (u64) nasid, (u64) subch, (u64) buf, (u64) len,
814 0, 0);
815 return (int) rv.v0;
816}
817
818/*
819 * Check whether any interrupts are pending for the system controller
820 * associated with 'nasid' and its subchannel 'subch'. The return
821 * value is a mask of pending interrupts (SAL_IROUTER_INTR_XMIT and/or
822 * SAL_IROUTER_INTR_RECV).
823 */
824static inline int
825ia64_sn_irtr_intr(nasid_t nasid, int subch)
826{
827 struct ia64_sal_retval rv;
828 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_STATUS,
829 (u64) nasid, (u64) subch, 0, 0, 0, 0);
830 return (int) rv.v0;
831}
832
833/*
834 * Enable the interrupt indicated by the intr parameter (either
835 * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
836 */
837static inline int
838ia64_sn_irtr_intr_enable(nasid_t nasid, int subch, u64 intr)
839{
840 struct ia64_sal_retval rv;
841 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_ON,
842 (u64) nasid, (u64) subch, intr, 0, 0, 0);
843 return (int) rv.v0;
844}
845
846/*
847 * Disable the interrupt indicated by the intr parameter (either
848 * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
849 */
850static inline int
851ia64_sn_irtr_intr_disable(nasid_t nasid, int subch, u64 intr)
852{
853 struct ia64_sal_retval rv;
854 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_OFF,
855 (u64) nasid, (u64) subch, intr, 0, 0, 0);
856 return (int) rv.v0;
857}
858
Greg Howard67639de2005-04-25 13:28:52 -0700859/*
860 * Set up a node as the point of contact for system controller
861 * environmental event delivery.
862 */
863static inline int
864ia64_sn_sysctl_event_init(nasid_t nasid)
865{
866 struct ia64_sal_retval rv;
867 SAL_CALL_REENTRANT(rv, SN_SAL_SYSCTL_EVENT, (u64) nasid,
868 0, 0, 0, 0, 0, 0);
869 return (int) rv.v0;
870}
871
Bruce Losure25732ad2005-09-02 15:16:35 -0500872/*
873 * Ask the system controller on the specified nasid to reset
874 * the CX corelet clock. Only valid on TIO nodes.
875 */
876static inline int
877ia64_sn_sysctl_tio_clock_reset(nasid_t nasid)
878{
879 struct ia64_sal_retval rv;
880 SAL_CALL_REENTRANT(rv, SN_SAL_SYSCTL_OP, SAL_SYSCTL_OP_TIO_JLCK_RST,
881 nasid, 0, 0, 0, 0, 0);
882 if (rv.status != 0)
883 return (int)rv.status;
884 if (rv.v0 != 0)
885 return (int)rv.v0;
886
887 return 0;
888}
889
890/*
891 * Get the associated ioboard type for a given nasid.
892 */
893static inline int
894ia64_sn_sysctl_ioboard_get(nasid_t nasid)
895{
896 struct ia64_sal_retval rv;
897 SAL_CALL_REENTRANT(rv, SN_SAL_SYSCTL_OP, SAL_SYSCTL_OP_IOBOARD,
898 nasid, 0, 0, 0, 0, 0);
899 if (rv.v0 != 0)
900 return (int)rv.v0;
901 if (rv.v1 != 0)
902 return (int)rv.v1;
903
904 return 0;
905}
906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907/**
908 * ia64_sn_get_fit_compt - read a FIT entry from the PROM header
909 * @nasid: NASID of node to read
910 * @index: FIT entry index to be retrieved (0..n)
911 * @fitentry: 16 byte buffer where FIT entry will be stored.
912 * @banbuf: optional buffer for retrieving banner
913 * @banlen: length of banner buffer
914 *
915 * Access to the physical PROM chips needs to be serialized since reads and
916 * writes can't occur at the same time, so we need to call into the SAL when
917 * we want to look at the FIT entries on the chips.
918 *
919 * Returns:
920 * %SALRET_OK if ok
921 * %SALRET_INVALID_ARG if index too big
922 * %SALRET_NOT_IMPLEMENTED if running on older PROM
923 * ??? if nasid invalid OR banner buffer not large enough
924 */
925static inline int
926ia64_sn_get_fit_compt(u64 nasid, u64 index, void *fitentry, void *banbuf,
927 u64 banlen)
928{
929 struct ia64_sal_retval rv;
930 SAL_CALL_NOLOCK(rv, SN_SAL_GET_FIT_COMPT, nasid, index, fitentry,
931 banbuf, banlen, 0, 0);
932 return (int) rv.status;
933}
934
935/*
936 * Initialize the SAL components of the system controller
937 * communication driver; specifically pass in a sizable buffer that
938 * can be used for allocation of subchannel queues as new subchannels
939 * are opened. "buf" points to the buffer, and "len" specifies its
940 * length.
941 */
942static inline int
943ia64_sn_irtr_init(nasid_t nasid, void *buf, int len)
944{
945 struct ia64_sal_retval rv;
946 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INIT,
947 (u64) nasid, (u64) buf, (u64) len, 0, 0, 0);
948 return (int) rv.status;
949}
950
951/*
952 * Returns the nasid, subnode & slice corresponding to a SAPIC ID
953 *
954 * In:
955 * arg0 - SN_SAL_GET_SAPIC_INFO
956 * arg1 - sapicid (lid >> 16)
957 * Out:
958 * v0 - nasid
959 * v1 - subnode
960 * v2 - slice
961 */
962static inline u64
963ia64_sn_get_sapic_info(int sapicid, int *nasid, int *subnode, int *slice)
964{
965 struct ia64_sal_retval ret_stuff;
966
967 ret_stuff.status = 0;
968 ret_stuff.v0 = 0;
969 ret_stuff.v1 = 0;
970 ret_stuff.v2 = 0;
971 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SAPIC_INFO, sapicid, 0, 0, 0, 0, 0, 0);
972
973/***** BEGIN HACK - temp til old proms no longer supported ********/
974 if (ret_stuff.status == SALRET_NOT_IMPLEMENTED) {
975 if (nasid) *nasid = sapicid & 0xfff;
976 if (subnode) *subnode = (sapicid >> 13) & 1;
977 if (slice) *slice = (sapicid >> 12) & 3;
978 return 0;
979 }
980/***** END HACK *******/
981
982 if (ret_stuff.status < 0)
983 return ret_stuff.status;
984
985 if (nasid) *nasid = (int) ret_stuff.v0;
986 if (subnode) *subnode = (int) ret_stuff.v1;
987 if (slice) *slice = (int) ret_stuff.v2;
988 return 0;
989}
990
991/*
992 * Returns information about the HUB/SHUB.
993 * In:
994 * arg0 - SN_SAL_GET_SN_INFO
995 * arg1 - 0 (other values reserved for future use)
996 * Out:
997 * v0
998 * [7:0] - shub type (0=shub1, 1=shub2)
999 * [15:8] - Log2 max number of nodes in entire system (includes
1000 * C-bricks, I-bricks, etc)
1001 * [23:16] - Log2 of nodes per sharing domain
1002 * [31:24] - partition ID
1003 * [39:32] - coherency_id
1004 * [47:40] - regionsize
1005 * v1
1006 * [15:0] - nasid mask (ex., 0x7ff for 11 bit nasid)
1007 * [23:15] - bit position of low nasid bit
1008 */
1009static inline u64
1010ia64_sn_get_sn_info(int fc, u8 *shubtype, u16 *nasid_bitmask, u8 *nasid_shift,
1011 u8 *systemsize, u8 *sharing_domain_size, u8 *partid, u8 *coher, u8 *reg)
1012{
1013 struct ia64_sal_retval ret_stuff;
1014
1015 ret_stuff.status = 0;
1016 ret_stuff.v0 = 0;
1017 ret_stuff.v1 = 0;
1018 ret_stuff.v2 = 0;
1019 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SN_INFO, fc, 0, 0, 0, 0, 0, 0);
1020
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 if (ret_stuff.status < 0)
1022 return ret_stuff.status;
1023
1024 if (shubtype) *shubtype = ret_stuff.v0 & 0xff;
1025 if (systemsize) *systemsize = (ret_stuff.v0 >> 8) & 0xff;
1026 if (sharing_domain_size) *sharing_domain_size = (ret_stuff.v0 >> 16) & 0xff;
1027 if (partid) *partid = (ret_stuff.v0 >> 24) & 0xff;
1028 if (coher) *coher = (ret_stuff.v0 >> 32) & 0xff;
1029 if (reg) *reg = (ret_stuff.v0 >> 40) & 0xff;
1030 if (nasid_bitmask) *nasid_bitmask = (ret_stuff.v1 & 0xffff);
1031 if (nasid_shift) *nasid_shift = (ret_stuff.v1 >> 16) & 0xff;
1032 return 0;
1033}
1034
1035/*
1036 * This is the access point to the Altix PROM hardware performance
1037 * and status monitoring interface. For info on using this, see
1038 * include/asm-ia64/sn/sn2/sn_hwperf.h
1039 */
1040static inline int
1041ia64_sn_hwperf_op(nasid_t nasid, u64 opcode, u64 a0, u64 a1, u64 a2,
1042 u64 a3, u64 a4, int *v0)
1043{
1044 struct ia64_sal_retval rv;
1045 SAL_CALL_NOLOCK(rv, SN_SAL_HWPERF_OP, (u64)nasid,
1046 opcode, a0, a1, a2, a3, a4);
1047 if (v0)
1048 *v0 = (int) rv.v0;
1049 return (int) rv.status;
1050}
1051
Mark Goodwin4a5c13c2005-04-25 13:04:22 -07001052static inline int
Mark Goodwinecc3c302005-08-16 00:50:00 -07001053ia64_sn_ioif_get_pci_topology(u64 buf, u64 len)
Mark Goodwin4a5c13c2005-04-25 13:04:22 -07001054{
1055 struct ia64_sal_retval rv;
Mark Goodwinecc3c302005-08-16 00:50:00 -07001056 SAL_CALL_NOLOCK(rv, SN_SAL_IOIF_GET_PCI_TOPOLOGY, buf, len, 0, 0, 0, 0, 0);
Mark Goodwin4a5c13c2005-04-25 13:04:22 -07001057 return (int) rv.status;
1058}
1059
Russ Anderson93a07d02005-04-25 13:19:52 -07001060/*
1061 * BTE error recovery is implemented in SAL
1062 */
1063static inline int
1064ia64_sn_bte_recovery(nasid_t nasid)
1065{
1066 struct ia64_sal_retval rv;
1067
1068 rv.status = 0;
1069 SAL_CALL_NOLOCK(rv, SN_SAL_BTE_RECOVER, 0, 0, 0, 0, 0, 0, 0);
1070 if (rv.status == SALRET_NOT_IMPLEMENTED)
1071 return 0;
1072 return (int) rv.status;
1073}
1074
Jack Steiner71a5d022005-05-10 08:01:00 -07001075static inline int
1076ia64_sn_is_fake_prom(void)
1077{
1078 struct ia64_sal_retval rv;
1079 SAL_CALL_NOLOCK(rv, SN_SAL_FAKE_PROM, 0, 0, 0, 0, 0, 0, 0);
1080 return (rv.status == 0);
1081}
1082
Jack Steinera1cddb82005-08-31 08:05:00 -07001083static inline int
1084ia64_sn_get_prom_feature_set(int set, unsigned long *feature_set)
1085{
1086 struct ia64_sal_retval rv;
1087
1088 SAL_CALL_NOLOCK(rv, SN_SAL_GET_PROM_FEATURE_SET, set, 0, 0, 0, 0, 0, 0);
1089 if (rv.status != 0)
1090 return rv.status;
1091 *feature_set = rv.v0;
1092 return 0;
1093}
1094
1095static inline int
1096ia64_sn_set_os_feature(int feature)
1097{
1098 struct ia64_sal_retval rv;
1099
1100 SAL_CALL_NOLOCK(rv, SN_SAL_SET_OS_FEATURE_SET, feature, 0, 0, 0, 0, 0, 0);
1101 return rv.status;
1102}
1103
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104#endif /* _ASM_IA64_SN_SN_SAL_H */