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