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