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