vserver 1.9.5.x5
[linux-2.6.git] / include / asm-ia64 / sn / sn_sal.h
1 #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  *
11  * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All rights reserved.
12  */
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
22 // SGI Specific Calls
23 #define  SN_SAL_POD_MODE                           0x02000001
24 #define  SN_SAL_SYSTEM_RESET                       0x02000002
25 #define  SN_SAL_PROBE                              0x02000003
26 #define  SN_SAL_GET_MASTER_NASID                   0x02000004
27 #define  SN_SAL_GET_KLCONFIG_ADDR                  0x02000005
28 #define  SN_SAL_LOG_CE                             0x02000006
29 #define  SN_SAL_REGISTER_CE                        0x02000007
30 #define  SN_SAL_GET_PARTITION_ADDR                 0x02000009
31 #define  SN_SAL_XP_ADDR_REGION                     0x0200000f
32 #define  SN_SAL_NO_FAULT_ZONE_VIRTUAL              0x02000010
33 #define  SN_SAL_NO_FAULT_ZONE_PHYSICAL             0x02000011
34 #define  SN_SAL_PRINT_ERROR                        0x02000012
35 #define  SN_SAL_SET_ERROR_HANDLING_FEATURES        0x0200001a   // reentrant
36 #define  SN_SAL_GET_FIT_COMPT                      0x0200001b   // reentrant
37 #define  SN_SAL_GET_HUB_INFO                       0x0200001c
38 #define  SN_SAL_GET_SAPIC_INFO                     0x0200001d
39 #define  SN_SAL_CONSOLE_PUTC                       0x02000021
40 #define  SN_SAL_CONSOLE_GETC                       0x02000022
41 #define  SN_SAL_CONSOLE_PUTS                       0x02000023
42 #define  SN_SAL_CONSOLE_GETS                       0x02000024
43 #define  SN_SAL_CONSOLE_GETS_TIMEOUT               0x02000025
44 #define  SN_SAL_CONSOLE_POLL                       0x02000026
45 #define  SN_SAL_CONSOLE_INTR                       0x02000027
46 #define  SN_SAL_CONSOLE_PUTB                       0x02000028
47 #define  SN_SAL_CONSOLE_XMIT_CHARS                 0x0200002a
48 #define  SN_SAL_CONSOLE_READC                      0x0200002b
49 #define  SN_SAL_SYSCTL_MODID_GET                   0x02000031
50 #define  SN_SAL_SYSCTL_GET                         0x02000032
51 #define  SN_SAL_SYSCTL_IOBRICK_MODULE_GET          0x02000033
52 #define  SN_SAL_SYSCTL_IO_PORTSPEED_GET            0x02000035
53 #define  SN_SAL_SYSCTL_SLAB_GET                    0x02000036
54 #define  SN_SAL_BUS_CONFIG                         0x02000037
55 #define  SN_SAL_SYS_SERIAL_GET                     0x02000038
56 #define  SN_SAL_PARTITION_SERIAL_GET               0x02000039
57 #define  SN_SAL_SYSCTL_PARTITION_GET               0x0200003a
58 #define  SN_SAL_SYSTEM_POWER_DOWN                  0x0200003b
59 #define  SN_SAL_GET_MASTER_BASEIO_NASID            0x0200003c
60 #define  SN_SAL_COHERENCE                          0x0200003d
61 #define  SN_SAL_MEMPROTECT                         0x0200003e
62 #define  SN_SAL_SYSCTL_FRU_CAPTURE                 0x0200003f
63
64 #define  SN_SAL_SYSCTL_IOBRICK_PCI_OP              0x02000042   // reentrant
65 #define  SN_SAL_IROUTER_OP                         0x02000043
66 #define  SN_SAL_IOIF_INTERRUPT                     0x0200004a
67 #define  SN_SAL_HWPERF_OP                          0x02000050   // lock
68 #define  SN_SAL_IOIF_ERROR_INTERRUPT               0x02000051
69
70 #define  SN_SAL_IOIF_SLOT_ENABLE                   0x02000053
71 #define  SN_SAL_IOIF_SLOT_DISABLE                  0x02000054
72 #define  SN_SAL_IOIF_GET_HUBDEV_INFO               0x02000055
73 #define  SN_SAL_IOIF_GET_PCIBUS_INFO               0x02000056
74 #define  SN_SAL_IOIF_GET_PCIDEV_INFO               0x02000057
75 #define  SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST      0x02000058
76
77 #define SN_SAL_HUB_ERROR_INTERRUPT                 0x02000060
78
79
80 /*
81  * Service-specific constants
82  */
83
84 /* Console interrupt manipulation */
85         /* action codes */
86 #define SAL_CONSOLE_INTR_OFF    0       /* turn the interrupt off */
87 #define SAL_CONSOLE_INTR_ON     1       /* turn the interrupt on */
88 #define SAL_CONSOLE_INTR_STATUS 2       /* retrieve the interrupt status */
89         /* interrupt specification & status return codes */
90 #define SAL_CONSOLE_INTR_XMIT   1       /* output interrupt */
91 #define SAL_CONSOLE_INTR_RECV   2       /* input interrupt */
92
93 /* interrupt handling */
94 #define SAL_INTR_ALLOC          1
95 #define SAL_INTR_FREE           2
96
97 /*
98  * IRouter (i.e. generalized system controller) operations
99  */
100 #define SAL_IROUTER_OPEN        0       /* open a subchannel */
101 #define SAL_IROUTER_CLOSE       1       /* close a subchannel */
102 #define SAL_IROUTER_SEND        2       /* send part of an IRouter packet */
103 #define SAL_IROUTER_RECV        3       /* receive part of an IRouter packet */
104 #define SAL_IROUTER_INTR_STATUS 4       /* check the interrupt status for
105                                          * an open subchannel
106                                          */
107 #define SAL_IROUTER_INTR_ON     5       /* enable an interrupt */
108 #define SAL_IROUTER_INTR_OFF    6       /* disable an interrupt */
109 #define SAL_IROUTER_INIT        7       /* initialize IRouter driver */
110
111 /* IRouter interrupt mask bits */
112 #define SAL_IROUTER_INTR_XMIT   SAL_CONSOLE_INTR_XMIT
113 #define SAL_IROUTER_INTR_RECV   SAL_CONSOLE_INTR_RECV
114
115
116 /*
117  * SAL Error Codes
118  */
119 #define SALRET_MORE_PASSES      1
120 #define SALRET_OK               0
121 #define SALRET_NOT_IMPLEMENTED  (-1)
122 #define SALRET_INVALID_ARG      (-2)
123 #define SALRET_ERROR            (-3)
124
125
126 /**
127  * sn_sal_rev_major - get the major SGI SAL revision number
128  *
129  * The SGI PROM stores its version in sal_[ab]_rev_(major|minor).
130  * This routine simply extracts the major value from the
131  * @ia64_sal_systab structure constructed by ia64_sal_init().
132  */
133 static inline int
134 sn_sal_rev_major(void)
135 {
136         struct ia64_sal_systab *systab = efi.sal_systab;
137
138         return (int)systab->sal_b_rev_major;
139 }
140
141 /**
142  * sn_sal_rev_minor - get the minor SGI SAL revision number
143  *
144  * The SGI PROM stores its version in sal_[ab]_rev_(major|minor).
145  * This routine simply extracts the minor value from the
146  * @ia64_sal_systab structure constructed by ia64_sal_init().
147  */
148 static inline int
149 sn_sal_rev_minor(void)
150 {
151         struct ia64_sal_systab *systab = efi.sal_systab;
152         
153         return (int)systab->sal_b_rev_minor;
154 }
155
156 /*
157  * Specify the minimum PROM revsion required for this kernel.
158  * Note that they're stored in hex format...
159  */
160 #define SN_SAL_MIN_MAJOR        0x4  /* SN2 kernels need at least PROM 4.0 */
161 #define SN_SAL_MIN_MINOR        0x0
162
163 /*
164  * Returns the master console nasid, if the call fails, return an illegal
165  * value.
166  */
167 static inline u64
168 ia64_sn_get_console_nasid(void)
169 {
170         struct ia64_sal_retval ret_stuff;
171
172         ret_stuff.status = 0;
173         ret_stuff.v0 = 0;
174         ret_stuff.v1 = 0;
175         ret_stuff.v2 = 0;
176         SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_NASID, 0, 0, 0, 0, 0, 0, 0);
177
178         if (ret_stuff.status < 0)
179                 return ret_stuff.status;
180
181         /* Master console nasid is in 'v0' */
182         return ret_stuff.v0;
183 }
184
185 /*
186  * Returns the master baseio nasid, if the call fails, return an illegal
187  * value.
188  */
189 static inline u64
190 ia64_sn_get_master_baseio_nasid(void)
191 {
192         struct ia64_sal_retval ret_stuff;
193
194         ret_stuff.status = 0;
195         ret_stuff.v0 = 0;
196         ret_stuff.v1 = 0;
197         ret_stuff.v2 = 0;
198         SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_BASEIO_NASID, 0, 0, 0, 0, 0, 0, 0);
199
200         if (ret_stuff.status < 0)
201                 return ret_stuff.status;
202
203         /* Master baseio nasid is in 'v0' */
204         return ret_stuff.v0;
205 }
206
207 static inline char *
208 ia64_sn_get_klconfig_addr(nasid_t nasid)
209 {
210         struct ia64_sal_retval ret_stuff;
211         int cnodeid;
212
213         cnodeid = nasid_to_cnodeid(nasid);
214         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);
219
220         /*
221          * We should panic if a valid cnode nasid does not produce
222          * a klconfig address.
223          */
224         if (ret_stuff.status != 0) {
225                 panic("ia64_sn_get_klconfig_addr: Returned error %lx\n", ret_stuff.status);
226         }
227         return ret_stuff.v0 ? __va(ret_stuff.v0) : NULL;
228 }
229
230 /*
231  * Returns the next console character.
232  */
233 static inline u64
234 ia64_sn_console_getc(int *ch)
235 {
236         struct ia64_sal_retval ret_stuff;
237
238         ret_stuff.status = 0;
239         ret_stuff.v0 = 0;
240         ret_stuff.v1 = 0;
241         ret_stuff.v2 = 0;
242         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_GETC, 0, 0, 0, 0, 0, 0, 0);
243
244         /* character is in 'v0' */
245         *ch = (int)ret_stuff.v0;
246
247         return ret_stuff.status;
248 }
249
250 /*
251  * Read a character from the SAL console device, after a previous interrupt
252  * or poll operation has given us to know that a character is available
253  * to be read.
254  */
255 static inline u64
256 ia64_sn_console_readc(void)
257 {
258         struct ia64_sal_retval ret_stuff;
259
260         ret_stuff.status = 0;
261         ret_stuff.v0 = 0;
262         ret_stuff.v1 = 0;
263         ret_stuff.v2 = 0;
264         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_READC, 0, 0, 0, 0, 0, 0, 0);
265
266         /* character is in 'v0' */
267         return ret_stuff.v0;
268 }
269
270 /*
271  * Sends the given character to the console.
272  */
273 static inline u64
274 ia64_sn_console_putc(char ch)
275 {
276         struct ia64_sal_retval ret_stuff;
277
278         ret_stuff.status = 0;
279         ret_stuff.v0 = 0;
280         ret_stuff.v1 = 0;
281         ret_stuff.v2 = 0;
282         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_PUTC, (uint64_t)ch, 0, 0, 0, 0, 0, 0);
283
284         return ret_stuff.status;
285 }
286
287 /*
288  * Sends the given buffer to the console.
289  */
290 static inline u64
291 ia64_sn_console_putb(const char *buf, int len)
292 {
293         struct ia64_sal_retval ret_stuff;
294
295         ret_stuff.status = 0;
296         ret_stuff.v0 = 0; 
297         ret_stuff.v1 = 0;
298         ret_stuff.v2 = 0;
299         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_PUTB, (uint64_t)buf, (uint64_t)len, 0, 0, 0, 0, 0);
300
301         if ( ret_stuff.status == 0 ) {
302                 return ret_stuff.v0;
303         }
304         return (u64)0;
305 }
306
307 /*
308  * Print a platform error record
309  */
310 static inline u64
311 ia64_sn_plat_specific_err_print(int (*hook)(const char*, ...), char *rec)
312 {
313         struct ia64_sal_retval ret_stuff;
314
315         ret_stuff.status = 0;
316         ret_stuff.v0 = 0;
317         ret_stuff.v1 = 0;
318         ret_stuff.v2 = 0;
319         SAL_CALL_REENTRANT(ret_stuff, SN_SAL_PRINT_ERROR, (uint64_t)hook, (uint64_t)rec, 0, 0, 0, 0, 0);
320
321         return ret_stuff.status;
322 }
323
324 /*
325  * Check for Platform errors
326  */
327 static inline u64
328 ia64_sn_plat_cpei_handler(void)
329 {
330         struct ia64_sal_retval ret_stuff;
331
332         ret_stuff.status = 0;
333         ret_stuff.v0 = 0;
334         ret_stuff.v1 = 0;
335         ret_stuff.v2 = 0;
336         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_LOG_CE, 0, 0, 0, 0, 0, 0, 0);
337
338         return ret_stuff.status;
339 }
340
341 /*
342  * Checks for console input.
343  */
344 static inline u64
345 ia64_sn_console_check(int *result)
346 {
347         struct ia64_sal_retval ret_stuff;
348
349         ret_stuff.status = 0;
350         ret_stuff.v0 = 0;
351         ret_stuff.v1 = 0;
352         ret_stuff.v2 = 0;
353         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_POLL, 0, 0, 0, 0, 0, 0, 0);
354
355         /* result is in 'v0' */
356         *result = (int)ret_stuff.v0;
357
358         return ret_stuff.status;
359 }
360
361 /*
362  * Checks console interrupt status
363  */
364 static inline u64
365 ia64_sn_console_intr_status(void)
366 {
367         struct ia64_sal_retval ret_stuff;
368
369         ret_stuff.status = 0;
370         ret_stuff.v0 = 0;
371         ret_stuff.v1 = 0;
372         ret_stuff.v2 = 0;
373         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_INTR, 
374                  0, SAL_CONSOLE_INTR_STATUS,
375                  0, 0, 0, 0, 0);
376
377         if (ret_stuff.status == 0) {
378             return ret_stuff.v0;
379         }
380         
381         return 0;
382 }
383
384 /*
385  * Enable an interrupt on the SAL console device.
386  */
387 static inline void
388 ia64_sn_console_intr_enable(uint64_t intr)
389 {
390         struct ia64_sal_retval ret_stuff;
391
392         ret_stuff.status = 0;
393         ret_stuff.v0 = 0;
394         ret_stuff.v1 = 0;
395         ret_stuff.v2 = 0;
396         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_INTR, 
397                  intr, SAL_CONSOLE_INTR_ON,
398                  0, 0, 0, 0, 0);
399 }
400
401 /*
402  * Disable an interrupt on the SAL console device.
403  */
404 static inline void
405 ia64_sn_console_intr_disable(uint64_t intr)
406 {
407         struct ia64_sal_retval ret_stuff;
408
409         ret_stuff.status = 0;
410         ret_stuff.v0 = 0;
411         ret_stuff.v1 = 0;
412         ret_stuff.v2 = 0;
413         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_INTR, 
414                  intr, SAL_CONSOLE_INTR_OFF,
415                  0, 0, 0, 0, 0);
416 }
417
418 /*
419  * Sends a character buffer to the console asynchronously.
420  */
421 static inline u64
422 ia64_sn_console_xmit_chars(char *buf, int len)
423 {
424         struct ia64_sal_retval ret_stuff;
425
426         ret_stuff.status = 0;
427         ret_stuff.v0 = 0;
428         ret_stuff.v1 = 0;
429         ret_stuff.v2 = 0;
430         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_XMIT_CHARS,
431                  (uint64_t)buf, (uint64_t)len,
432                  0, 0, 0, 0, 0);
433
434         if (ret_stuff.status == 0) {
435             return ret_stuff.v0;
436         }
437
438         return 0;
439 }
440
441 /*
442  * Returns the iobrick module Id
443  */
444 static inline u64
445 ia64_sn_sysctl_iobrick_module_get(nasid_t nasid, int *result)
446 {
447         struct ia64_sal_retval ret_stuff;
448
449         ret_stuff.status = 0;
450         ret_stuff.v0 = 0;
451         ret_stuff.v1 = 0;
452         ret_stuff.v2 = 0;
453         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_SYSCTL_IOBRICK_MODULE_GET, nasid, 0, 0, 0, 0, 0, 0);
454
455         /* result is in 'v0' */
456         *result = (int)ret_stuff.v0;
457
458         return ret_stuff.status;
459 }
460
461 /**
462  * ia64_sn_pod_mode - call the SN_SAL_POD_MODE function
463  *
464  * SN_SAL_POD_MODE actually takes an argument, but it's always
465  * 0 when we call it from the kernel, so we don't have to expose
466  * it to the caller.
467  */
468 static inline u64
469 ia64_sn_pod_mode(void)
470 {
471         struct ia64_sal_retval isrv;
472         SAL_CALL(isrv, SN_SAL_POD_MODE, 0, 0, 0, 0, 0, 0, 0);
473         if (isrv.status)
474                 return 0;
475         return isrv.v0;
476 }
477
478 /**
479  * ia64_sn_probe_mem - read from memory safely
480  * @addr: address to probe
481  * @size: number bytes to read (1,2,4,8)
482  * @data_ptr: address to store value read by probe (-1 returned if probe fails)
483  *
484  * Call into the SAL to do a memory read.  If the read generates a machine
485  * check, this routine will recover gracefully and return -1 to the caller.
486  * @addr is usually a kernel virtual address in uncached space (i.e. the
487  * address starts with 0xc), but if called in physical mode, @addr should
488  * be a physical address.
489  *
490  * Return values:
491  *  0 - probe successful
492  *  1 - probe failed (generated MCA)
493  *  2 - Bad arg
494  * <0 - PAL error
495  */
496 static inline u64
497 ia64_sn_probe_mem(long addr, long size, void *data_ptr)
498 {
499         struct ia64_sal_retval isrv;
500
501         SAL_CALL(isrv, SN_SAL_PROBE, addr, size, 0, 0, 0, 0, 0);
502
503         if (data_ptr) {
504                 switch (size) {
505                 case 1:
506                         *((u8*)data_ptr) = (u8)isrv.v0;
507                         break;
508                 case 2:
509                         *((u16*)data_ptr) = (u16)isrv.v0;
510                         break;
511                 case 4:
512                         *((u32*)data_ptr) = (u32)isrv.v0;
513                         break;
514                 case 8:
515                         *((u64*)data_ptr) = (u64)isrv.v0;
516                         break;
517                 default:
518                         isrv.status = 2;
519                 }
520         }
521         return isrv.status;
522 }
523
524 /*
525  * Retrieve the system serial number as an ASCII string.
526  */
527 static inline u64
528 ia64_sn_sys_serial_get(char *buf)
529 {
530         struct ia64_sal_retval ret_stuff;
531         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_SYS_SERIAL_GET, buf, 0, 0, 0, 0, 0, 0);
532         return ret_stuff.status;
533 }
534
535 extern char sn_system_serial_number_string[];
536 extern u64 sn_partition_serial_number;
537
538 static inline char *
539 sn_system_serial_number(void) {
540         if (sn_system_serial_number_string[0]) {
541                 return(sn_system_serial_number_string);
542         } else {
543                 ia64_sn_sys_serial_get(sn_system_serial_number_string);
544                 return(sn_system_serial_number_string);
545         }
546 }
547         
548
549 /*
550  * Returns a unique id number for this system and partition (suitable for
551  * use with license managers), based in part on the system serial number.
552  */
553 static inline u64
554 ia64_sn_partition_serial_get(void)
555 {
556         struct ia64_sal_retval ret_stuff;
557         SAL_CALL(ret_stuff, SN_SAL_PARTITION_SERIAL_GET, 0, 0, 0, 0, 0, 0, 0);
558         if (ret_stuff.status != 0)
559             return 0;
560         return ret_stuff.v0;
561 }
562
563 static inline u64
564 sn_partition_serial_number_val(void) {
565         if (sn_partition_serial_number) {
566                 return(sn_partition_serial_number);
567         } else {
568                 return(sn_partition_serial_number = ia64_sn_partition_serial_get());
569         }
570 }
571
572 /*
573  * Returns the partition id of the nasid passed in as an argument,
574  * or INVALID_PARTID if the partition id cannot be retrieved.
575  */
576 static inline partid_t
577 ia64_sn_sysctl_partition_get(nasid_t nasid)
578 {
579         struct ia64_sal_retval ret_stuff;
580         SAL_CALL(ret_stuff, SN_SAL_SYSCTL_PARTITION_GET, nasid,
581                  0, 0, 0, 0, 0, 0);
582         if (ret_stuff.status != 0)
583             return INVALID_PARTID;
584         return ((partid_t)ret_stuff.v0);
585 }
586
587 /*
588  * Returns the partition id of the current processor.
589  */
590
591 extern partid_t sn_partid;
592
593 static inline partid_t
594 sn_local_partid(void) {
595         if (sn_partid < 0) {
596                 return (sn_partid = ia64_sn_sysctl_partition_get(cpuid_to_nasid(smp_processor_id())));
597         } else {
598                 return sn_partid;
599         }
600 }
601
602 /*
603  * Register or unregister a physical address range being referenced across
604  * a partition boundary for which certain SAL errors should be scanned for,
605  * cleaned up and ignored.  This is of value for kernel partitioning code only.
606  * Values for the operation argument:
607  *      1 = register this address range with SAL
608  *      0 = unregister this address range with SAL
609  * 
610  * SAL maintains a reference count on an address range in case it is registered
611  * multiple times.
612  * 
613  * On success, returns the reference count of the address range after the SAL
614  * call has performed the current registration/unregistration.  Returns a
615  * negative value if an error occurred.
616  */
617 static inline int
618 sn_register_xp_addr_region(u64 paddr, u64 len, int operation)
619 {
620         struct ia64_sal_retval ret_stuff;
621         SAL_CALL(ret_stuff, SN_SAL_XP_ADDR_REGION, paddr, len, (u64)operation,
622                  0, 0, 0, 0);
623         return ret_stuff.status;
624 }
625
626 /*
627  * Register or unregister an instruction range for which SAL errors should
628  * be ignored.  If an error occurs while in the registered range, SAL jumps
629  * to return_addr after ignoring the error.  Values for the operation argument:
630  *      1 = register this instruction range with SAL
631  *      0 = unregister this instruction range with SAL
632  *
633  * Returns 0 on success, or a negative value if an error occurred.
634  */
635 static inline int
636 sn_register_nofault_code(u64 start_addr, u64 end_addr, u64 return_addr,
637                          int virtual, int operation)
638 {
639         struct ia64_sal_retval ret_stuff;
640         u64 call;
641         if (virtual) {
642                 call = SN_SAL_NO_FAULT_ZONE_VIRTUAL;
643         } else {
644                 call = SN_SAL_NO_FAULT_ZONE_PHYSICAL;
645         }
646         SAL_CALL(ret_stuff, call, start_addr, end_addr, return_addr, (u64)1,
647                  0, 0, 0);
648         return ret_stuff.status;
649 }
650
651 /*
652  * Change or query the coherence domain for this partition. Each cpu-based
653  * nasid is represented by a bit in an array of 64-bit words:
654  *      0 = not in this partition's coherency domain
655  *      1 = in this partition's coherency domain
656  *
657  * It is not possible for the local system's nasids to be removed from
658  * the coherency domain.  Purpose of the domain arguments:
659  *      new_domain = set the coherence domain to the given nasids
660  *      old_domain = return the current coherence domain
661  *
662  * Returns 0 on success, or a negative value if an error occurred.
663  */
664 static inline int
665 sn_change_coherence(u64 *new_domain, u64 *old_domain)
666 {
667         struct ia64_sal_retval ret_stuff;
668         SAL_CALL(ret_stuff, SN_SAL_COHERENCE, new_domain, old_domain, 0, 0,
669                  0, 0, 0);
670         return ret_stuff.status;
671 }
672
673 /*
674  * Change memory access protections for a physical address range.
675  * nasid_array is not used on Altix, but may be in future architectures.
676  * Available memory protection access classes are defined after the function.
677  */
678 static inline int
679 sn_change_memprotect(u64 paddr, u64 len, u64 perms, u64 *nasid_array)
680 {
681         struct ia64_sal_retval ret_stuff;
682         int cnodeid;
683         unsigned long irq_flags;
684
685         cnodeid = nasid_to_cnodeid(get_node_number(paddr));
686         // spin_lock(&NODEPDA(cnodeid)->bist_lock);
687         local_irq_save(irq_flags);
688         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_MEMPROTECT, paddr, len, nasid_array,
689                  perms, 0, 0, 0);
690         local_irq_restore(irq_flags);
691         // spin_unlock(&NODEPDA(cnodeid)->bist_lock);
692         return ret_stuff.status;
693 }
694 #define SN_MEMPROT_ACCESS_CLASS_0               0x14a080
695 #define SN_MEMPROT_ACCESS_CLASS_1               0x2520c2
696 #define SN_MEMPROT_ACCESS_CLASS_2               0x14a1ca
697 #define SN_MEMPROT_ACCESS_CLASS_3               0x14a290
698 #define SN_MEMPROT_ACCESS_CLASS_6               0x084080
699 #define SN_MEMPROT_ACCESS_CLASS_7               0x021080
700
701 /*
702  * Turns off system power.
703  */
704 static inline void
705 ia64_sn_power_down(void)
706 {
707         struct ia64_sal_retval ret_stuff;
708         SAL_CALL(ret_stuff, SN_SAL_SYSTEM_POWER_DOWN, 0, 0, 0, 0, 0, 0, 0);
709         while(1);
710         /* never returns */
711 }
712
713 /**
714  * ia64_sn_fru_capture - tell the system controller to capture hw state
715  *
716  * This routine will call the SAL which will tell the system controller(s)
717  * to capture hw mmr information from each SHub in the system.
718  */
719 static inline u64
720 ia64_sn_fru_capture(void)
721 {
722         struct ia64_sal_retval isrv;
723         SAL_CALL(isrv, SN_SAL_SYSCTL_FRU_CAPTURE, 0, 0, 0, 0, 0, 0, 0);
724         if (isrv.status)
725                 return 0;
726         return isrv.v0;
727 }
728
729 /*
730  * Performs an operation on a PCI bus or slot -- power up, power down
731  * or reset.
732  */
733 static inline u64
734 ia64_sn_sysctl_iobrick_pci_op(nasid_t n, u64 connection_type, 
735                               u64 bus, char slot, 
736                               u64 action)
737 {
738         struct ia64_sal_retval rv = {0, 0, 0, 0};
739
740         SAL_CALL_NOLOCK(rv, SN_SAL_SYSCTL_IOBRICK_PCI_OP, connection_type, n, action,
741                  bus, (u64) slot, 0, 0);
742         if (rv.status)
743                 return rv.v0;
744         return 0;
745 }
746
747
748 /*
749  * Open a subchannel for sending arbitrary data to the system
750  * controller network via the system controller device associated with
751  * 'nasid'.  Return the subchannel number or a negative error code.
752  */
753 static inline int
754 ia64_sn_irtr_open(nasid_t nasid)
755 {
756         struct ia64_sal_retval rv;
757         SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_OPEN, nasid,
758                            0, 0, 0, 0, 0);
759         return (int) rv.v0;
760 }
761
762 /*
763  * Close system controller subchannel 'subch' previously opened on 'nasid'.
764  */
765 static inline int
766 ia64_sn_irtr_close(nasid_t nasid, int subch)
767 {
768         struct ia64_sal_retval rv;
769         SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_CLOSE,
770                            (u64) nasid, (u64) subch, 0, 0, 0, 0);
771         return (int) rv.status;
772 }
773
774 /*
775  * Read data from system controller associated with 'nasid' on
776  * subchannel 'subch'.  The buffer to be filled is pointed to by
777  * 'buf', and its capacity is in the integer pointed to by 'len'.  The
778  * referent of 'len' is set to the number of bytes read by the SAL
779  * call.  The return value is either SALRET_OK (for bytes read) or
780  * SALRET_ERROR (for error or "no data available").
781  */
782 static inline int
783 ia64_sn_irtr_recv(nasid_t nasid, int subch, char *buf, int *len)
784 {
785         struct ia64_sal_retval rv;
786         SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_RECV,
787                            (u64) nasid, (u64) subch, (u64) buf, (u64) len,
788                            0, 0);
789         return (int) rv.status;
790 }
791
792 /*
793  * Write data to the system controller network via the system
794  * controller associated with 'nasid' on suchannel 'subch'.  The
795  * buffer to be written out is pointed to by 'buf', and 'len' is the
796  * number of bytes to be written.  The return value is either the
797  * number of bytes written (which could be zero) or a negative error
798  * code.
799  */
800 static inline int
801 ia64_sn_irtr_send(nasid_t nasid, int subch, char *buf, int len)
802 {
803         struct ia64_sal_retval rv;
804         SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_SEND,
805                            (u64) nasid, (u64) subch, (u64) buf, (u64) len,
806                            0, 0);
807         return (int) rv.v0;
808 }
809
810 /*
811  * Check whether any interrupts are pending for the system controller
812  * associated with 'nasid' and its subchannel 'subch'.  The return
813  * value is a mask of pending interrupts (SAL_IROUTER_INTR_XMIT and/or
814  * SAL_IROUTER_INTR_RECV).
815  */
816 static inline int
817 ia64_sn_irtr_intr(nasid_t nasid, int subch)
818 {
819         struct ia64_sal_retval rv;
820         SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_STATUS,
821                            (u64) nasid, (u64) subch, 0, 0, 0, 0);
822         return (int) rv.v0;
823 }
824
825 /*
826  * Enable the interrupt indicated by the intr parameter (either
827  * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
828  */
829 static inline int
830 ia64_sn_irtr_intr_enable(nasid_t nasid, int subch, u64 intr)
831 {
832         struct ia64_sal_retval rv;
833         SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_ON,
834                            (u64) nasid, (u64) subch, intr, 0, 0, 0);
835         return (int) rv.v0;
836 }
837
838 /*
839  * Disable the interrupt indicated by the intr parameter (either
840  * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
841  */
842 static inline int
843 ia64_sn_irtr_intr_disable(nasid_t nasid, int subch, u64 intr)
844 {
845         struct ia64_sal_retval rv;
846         SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_OFF,
847                            (u64) nasid, (u64) subch, intr, 0, 0, 0);
848         return (int) rv.v0;
849 }
850
851 /**
852  * ia64_sn_get_fit_compt - read a FIT entry from the PROM header
853  * @nasid: NASID of node to read
854  * @index: FIT entry index to be retrieved (0..n)
855  * @fitentry: 16 byte buffer where FIT entry will be stored.
856  * @banbuf: optional buffer for retrieving banner
857  * @banlen: length of banner buffer
858  *
859  * Access to the physical PROM chips needs to be serialized since reads and
860  * writes can't occur at the same time, so we need to call into the SAL when
861  * we want to look at the FIT entries on the chips.
862  *
863  * Returns:
864  *      %SALRET_OK if ok
865  *      %SALRET_INVALID_ARG if index too big
866  *      %SALRET_NOT_IMPLEMENTED if running on older PROM
867  *      ??? if nasid invalid OR banner buffer not large enough
868  */
869 static inline int
870 ia64_sn_get_fit_compt(u64 nasid, u64 index, void *fitentry, void *banbuf,
871                       u64 banlen)
872 {
873         struct ia64_sal_retval rv;
874         SAL_CALL_NOLOCK(rv, SN_SAL_GET_FIT_COMPT, nasid, index, fitentry,
875                         banbuf, banlen, 0, 0);
876         return (int) rv.status;
877 }
878
879 /*
880  * Initialize the SAL components of the system controller
881  * communication driver; specifically pass in a sizable buffer that
882  * can be used for allocation of subchannel queues as new subchannels
883  * are opened.  "buf" points to the buffer, and "len" specifies its
884  * length.
885  */
886 static inline int
887 ia64_sn_irtr_init(nasid_t nasid, void *buf, int len)
888 {
889         struct ia64_sal_retval rv;
890         SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INIT,
891                            (u64) nasid, (u64) buf, (u64) len, 0, 0, 0);
892         return (int) rv.status;
893 }
894
895 /*
896  * Returns the nasid, subnode & slice corresponding to a SAPIC ID
897  *
898  *  In:
899  *      arg0 - SN_SAL_GET_SAPIC_INFO
900  *      arg1 - sapicid (lid >> 16) 
901  *  Out:
902  *      v0 - nasid
903  *      v1 - subnode
904  *      v2 - slice
905  */
906 static inline u64
907 ia64_sn_get_sapic_info(int sapicid, int *nasid, int *subnode, int *slice)
908 {
909         struct ia64_sal_retval ret_stuff;
910
911         ret_stuff.status = 0;
912         ret_stuff.v0 = 0;
913         ret_stuff.v1 = 0;
914         ret_stuff.v2 = 0;
915         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SAPIC_INFO, sapicid, 0, 0, 0, 0, 0, 0);
916
917 /***** BEGIN HACK - temp til old proms no longer supported ********/
918         if (ret_stuff.status == SALRET_NOT_IMPLEMENTED) {
919                 if (nasid) *nasid = sapicid & 0xfff;
920                 if (subnode) *subnode = (sapicid >> 13) & 1;
921                 if (slice) *slice = (sapicid >> 12) & 3;
922                 return 0;
923         }
924 /***** END HACK *******/
925
926         if (ret_stuff.status < 0)
927                 return ret_stuff.status;
928
929         if (nasid) *nasid = (int) ret_stuff.v0;
930         if (subnode) *subnode = (int) ret_stuff.v1;
931         if (slice) *slice = (int) ret_stuff.v2;
932         return 0;
933 }
934  
935 /*
936  * Returns information about the HUB/SHUB.
937  *  In:
938  *      arg0 - SN_SAL_GET_HUB_INFO
939  *      arg1 - 0 (other values reserved for future use)
940  *  Out:
941  *      v0 - shub type (0=shub1, 1=shub2)
942  *      v1 - masid mask (ex., 0x7ff for 11 bit nasid)
943  *      v2 - bit position of low nasid bit
944  */
945 static inline u64
946 ia64_sn_get_hub_info(int fc, u64 *arg1, u64 *arg2, u64 *arg3)
947 {
948         struct ia64_sal_retval ret_stuff;
949
950         ret_stuff.status = 0;
951         ret_stuff.v0 = 0;
952         ret_stuff.v1 = 0;
953         ret_stuff.v2 = 0;
954         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_HUB_INFO, fc, 0, 0, 0, 0, 0, 0);
955
956 /***** BEGIN HACK - temp til old proms no longer supported ********/
957         if (ret_stuff.status == SALRET_NOT_IMPLEMENTED) {
958                 if (arg1) *arg1 = 0;
959                 if (arg2) *arg2 = 0x7ff;
960                 if (arg3) *arg3 = 38;
961                 return 0;
962         }
963 /***** END HACK *******/
964
965         if (ret_stuff.status < 0)
966                 return ret_stuff.status;
967
968         if (arg1) *arg1 = ret_stuff.v0;
969         if (arg2) *arg2 = ret_stuff.v1;
970         if (arg3) *arg3 = ret_stuff.v2;
971         return 0;
972 }
973  
974 /*
975  * This is the access point to the Altix PROM hardware performance
976  * and status monitoring interface. For info on using this, see
977  * include/asm-ia64/sn/sn2/sn_hwperf.h
978  */
979 static inline int
980 ia64_sn_hwperf_op(nasid_t nasid, u64 opcode, u64 a0, u64 a1, u64 a2,
981                   u64 a3, u64 a4, int *v0)
982 {
983         struct ia64_sal_retval rv;
984         SAL_CALL_NOLOCK(rv, SN_SAL_HWPERF_OP, (u64)nasid,
985                 opcode, a0, a1, a2, a3, a4);
986         if (v0)
987                 *v0 = (int) rv.v0;
988         return (int) rv.status;
989 }
990
991 #endif /* _ASM_IA64_SN_SN_SAL_H */