[IA64-SGI] Shub2 BTE support - BTE recovery code
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / asm-ia64 / sn / sn_sal.h
blob581f9a783045c8cff79e1116a45d7e4794d3ecec
1 #ifndef _ASM_IA64_SN_SN_SAL_H
2 #define _ASM_IA64_SN_SN_SAL_H
4 /*
5 * System Abstraction Layer definitions for IA64
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.
11 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All rights reserved.
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>
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_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
65 #define SN_SAL_SYSCTL_IOBRICK_PCI_OP 0x02000042 // reentrant
66 #define SN_SAL_IROUTER_OP 0x02000043
67 #define SN_SAL_IOIF_INTERRUPT 0x0200004a
68 #define SN_SAL_HWPERF_OP 0x02000050 // lock
69 #define SN_SAL_IOIF_ERROR_INTERRUPT 0x02000051
71 #define SN_SAL_IOIF_SLOT_ENABLE 0x02000053
72 #define SN_SAL_IOIF_SLOT_DISABLE 0x02000054
73 #define SN_SAL_IOIF_GET_HUBDEV_INFO 0x02000055
74 #define SN_SAL_IOIF_GET_PCIBUS_INFO 0x02000056
75 #define SN_SAL_IOIF_GET_PCIDEV_INFO 0x02000057
76 #define SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST 0x02000058
77 #define SN_SAL_IOIF_GET_PCI_TOPOLOGY 0x02000059
79 #define SN_SAL_HUB_ERROR_INTERRUPT 0x02000060
80 #define SN_SAL_BTE_RECOVER 0x02000061
83 * Service-specific constants
86 /* Console interrupt manipulation */
87 /* action codes */
88 #define SAL_CONSOLE_INTR_OFF 0 /* turn the interrupt off */
89 #define SAL_CONSOLE_INTR_ON 1 /* turn the interrupt on */
90 #define SAL_CONSOLE_INTR_STATUS 2 /* retrieve the interrupt status */
91 /* interrupt specification & status return codes */
92 #define SAL_CONSOLE_INTR_XMIT 1 /* output interrupt */
93 #define SAL_CONSOLE_INTR_RECV 2 /* input interrupt */
95 /* interrupt handling */
96 #define SAL_INTR_ALLOC 1
97 #define SAL_INTR_FREE 2
100 * IRouter (i.e. generalized system controller) operations
102 #define SAL_IROUTER_OPEN 0 /* open a subchannel */
103 #define SAL_IROUTER_CLOSE 1 /* close a subchannel */
104 #define SAL_IROUTER_SEND 2 /* send part of an IRouter packet */
105 #define SAL_IROUTER_RECV 3 /* receive part of an IRouter packet */
106 #define SAL_IROUTER_INTR_STATUS 4 /* check the interrupt status for
107 * an open subchannel
109 #define SAL_IROUTER_INTR_ON 5 /* enable an interrupt */
110 #define SAL_IROUTER_INTR_OFF 6 /* disable an interrupt */
111 #define SAL_IROUTER_INIT 7 /* initialize IRouter driver */
113 /* IRouter interrupt mask bits */
114 #define SAL_IROUTER_INTR_XMIT SAL_CONSOLE_INTR_XMIT
115 #define SAL_IROUTER_INTR_RECV SAL_CONSOLE_INTR_RECV
119 * SAL Error Codes
121 #define SALRET_MORE_PASSES 1
122 #define SALRET_OK 0
123 #define SALRET_NOT_IMPLEMENTED (-1)
124 #define SALRET_INVALID_ARG (-2)
125 #define SALRET_ERROR (-3)
129 * sn_sal_rev_major - get the major SGI SAL revision number
131 * The SGI PROM stores its version in sal_[ab]_rev_(major|minor).
132 * This routine simply extracts the major value from the
133 * @ia64_sal_systab structure constructed by ia64_sal_init().
135 static inline int
136 sn_sal_rev_major(void)
138 struct ia64_sal_systab *systab = efi.sal_systab;
140 return (int)systab->sal_b_rev_major;
144 * sn_sal_rev_minor - get the minor SGI SAL revision number
146 * The SGI PROM stores its version in sal_[ab]_rev_(major|minor).
147 * This routine simply extracts the minor value from the
148 * @ia64_sal_systab structure constructed by ia64_sal_init().
150 static inline int
151 sn_sal_rev_minor(void)
153 struct ia64_sal_systab *systab = efi.sal_systab;
155 return (int)systab->sal_b_rev_minor;
159 * Specify the minimum PROM revsion required for this kernel.
160 * Note that they're stored in hex format...
162 #define SN_SAL_MIN_MAJOR 0x4 /* SN2 kernels need at least PROM 4.0 */
163 #define SN_SAL_MIN_MINOR 0x0
166 * Returns the master console nasid, if the call fails, return an illegal
167 * value.
169 static inline u64
170 ia64_sn_get_console_nasid(void)
172 struct ia64_sal_retval ret_stuff;
174 ret_stuff.status = 0;
175 ret_stuff.v0 = 0;
176 ret_stuff.v1 = 0;
177 ret_stuff.v2 = 0;
178 SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_NASID, 0, 0, 0, 0, 0, 0, 0);
180 if (ret_stuff.status < 0)
181 return ret_stuff.status;
183 /* Master console nasid is in 'v0' */
184 return ret_stuff.v0;
188 * Returns the master baseio nasid, if the call fails, return an illegal
189 * value.
191 static inline u64
192 ia64_sn_get_master_baseio_nasid(void)
194 struct ia64_sal_retval ret_stuff;
196 ret_stuff.status = 0;
197 ret_stuff.v0 = 0;
198 ret_stuff.v1 = 0;
199 ret_stuff.v2 = 0;
200 SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_BASEIO_NASID, 0, 0, 0, 0, 0, 0, 0);
202 if (ret_stuff.status < 0)
203 return ret_stuff.status;
205 /* Master baseio nasid is in 'v0' */
206 return ret_stuff.v0;
209 static inline char *
210 ia64_sn_get_klconfig_addr(nasid_t nasid)
212 struct ia64_sal_retval ret_stuff;
213 int cnodeid;
215 cnodeid = nasid_to_cnodeid(nasid);
216 ret_stuff.status = 0;
217 ret_stuff.v0 = 0;
218 ret_stuff.v1 = 0;
219 ret_stuff.v2 = 0;
220 SAL_CALL(ret_stuff, SN_SAL_GET_KLCONFIG_ADDR, (u64)nasid, 0, 0, 0, 0, 0, 0);
223 * We should panic if a valid cnode nasid does not produce
224 * a klconfig address.
226 if (ret_stuff.status != 0) {
227 panic("ia64_sn_get_klconfig_addr: Returned error %lx\n", ret_stuff.status);
229 return ret_stuff.v0 ? __va(ret_stuff.v0) : NULL;
233 * Returns the next console character.
235 static inline u64
236 ia64_sn_console_getc(int *ch)
238 struct ia64_sal_retval ret_stuff;
240 ret_stuff.status = 0;
241 ret_stuff.v0 = 0;
242 ret_stuff.v1 = 0;
243 ret_stuff.v2 = 0;
244 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_GETC, 0, 0, 0, 0, 0, 0, 0);
246 /* character is in 'v0' */
247 *ch = (int)ret_stuff.v0;
249 return ret_stuff.status;
253 * Read a character from the SAL console device, after a previous interrupt
254 * or poll operation has given us to know that a character is available
255 * to be read.
257 static inline u64
258 ia64_sn_console_readc(void)
260 struct ia64_sal_retval ret_stuff;
262 ret_stuff.status = 0;
263 ret_stuff.v0 = 0;
264 ret_stuff.v1 = 0;
265 ret_stuff.v2 = 0;
266 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_READC, 0, 0, 0, 0, 0, 0, 0);
268 /* character is in 'v0' */
269 return ret_stuff.v0;
273 * Sends the given character to the console.
275 static inline u64
276 ia64_sn_console_putc(char ch)
278 struct ia64_sal_retval ret_stuff;
280 ret_stuff.status = 0;
281 ret_stuff.v0 = 0;
282 ret_stuff.v1 = 0;
283 ret_stuff.v2 = 0;
284 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_PUTC, (uint64_t)ch, 0, 0, 0, 0, 0, 0);
286 return ret_stuff.status;
290 * Sends the given buffer to the console.
292 static inline u64
293 ia64_sn_console_putb(const char *buf, int len)
295 struct ia64_sal_retval ret_stuff;
297 ret_stuff.status = 0;
298 ret_stuff.v0 = 0;
299 ret_stuff.v1 = 0;
300 ret_stuff.v2 = 0;
301 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_PUTB, (uint64_t)buf, (uint64_t)len, 0, 0, 0, 0, 0);
303 if ( ret_stuff.status == 0 ) {
304 return ret_stuff.v0;
306 return (u64)0;
310 * Print a platform error record
312 static inline u64
313 ia64_sn_plat_specific_err_print(int (*hook)(const char*, ...), char *rec)
315 struct ia64_sal_retval ret_stuff;
317 ret_stuff.status = 0;
318 ret_stuff.v0 = 0;
319 ret_stuff.v1 = 0;
320 ret_stuff.v2 = 0;
321 SAL_CALL_REENTRANT(ret_stuff, SN_SAL_PRINT_ERROR, (uint64_t)hook, (uint64_t)rec, 0, 0, 0, 0, 0);
323 return ret_stuff.status;
327 * Check for Platform errors
329 static inline u64
330 ia64_sn_plat_cpei_handler(void)
332 struct ia64_sal_retval ret_stuff;
334 ret_stuff.status = 0;
335 ret_stuff.v0 = 0;
336 ret_stuff.v1 = 0;
337 ret_stuff.v2 = 0;
338 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_LOG_CE, 0, 0, 0, 0, 0, 0, 0);
340 return ret_stuff.status;
344 * Checks for console input.
346 static inline u64
347 ia64_sn_console_check(int *result)
349 struct ia64_sal_retval ret_stuff;
351 ret_stuff.status = 0;
352 ret_stuff.v0 = 0;
353 ret_stuff.v1 = 0;
354 ret_stuff.v2 = 0;
355 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_POLL, 0, 0, 0, 0, 0, 0, 0);
357 /* result is in 'v0' */
358 *result = (int)ret_stuff.v0;
360 return ret_stuff.status;
364 * Checks console interrupt status
366 static inline u64
367 ia64_sn_console_intr_status(void)
369 struct ia64_sal_retval ret_stuff;
371 ret_stuff.status = 0;
372 ret_stuff.v0 = 0;
373 ret_stuff.v1 = 0;
374 ret_stuff.v2 = 0;
375 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_INTR,
376 0, SAL_CONSOLE_INTR_STATUS,
377 0, 0, 0, 0, 0);
379 if (ret_stuff.status == 0) {
380 return ret_stuff.v0;
383 return 0;
387 * Enable an interrupt on the SAL console device.
389 static inline void
390 ia64_sn_console_intr_enable(uint64_t intr)
392 struct ia64_sal_retval ret_stuff;
394 ret_stuff.status = 0;
395 ret_stuff.v0 = 0;
396 ret_stuff.v1 = 0;
397 ret_stuff.v2 = 0;
398 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_INTR,
399 intr, SAL_CONSOLE_INTR_ON,
400 0, 0, 0, 0, 0);
404 * Disable an interrupt on the SAL console device.
406 static inline void
407 ia64_sn_console_intr_disable(uint64_t intr)
409 struct ia64_sal_retval ret_stuff;
411 ret_stuff.status = 0;
412 ret_stuff.v0 = 0;
413 ret_stuff.v1 = 0;
414 ret_stuff.v2 = 0;
415 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_INTR,
416 intr, SAL_CONSOLE_INTR_OFF,
417 0, 0, 0, 0, 0);
421 * Sends a character buffer to the console asynchronously.
423 static inline u64
424 ia64_sn_console_xmit_chars(char *buf, int len)
426 struct ia64_sal_retval ret_stuff;
428 ret_stuff.status = 0;
429 ret_stuff.v0 = 0;
430 ret_stuff.v1 = 0;
431 ret_stuff.v2 = 0;
432 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_XMIT_CHARS,
433 (uint64_t)buf, (uint64_t)len,
434 0, 0, 0, 0, 0);
436 if (ret_stuff.status == 0) {
437 return ret_stuff.v0;
440 return 0;
444 * Returns the iobrick module Id
446 static inline u64
447 ia64_sn_sysctl_iobrick_module_get(nasid_t nasid, int *result)
449 struct ia64_sal_retval ret_stuff;
451 ret_stuff.status = 0;
452 ret_stuff.v0 = 0;
453 ret_stuff.v1 = 0;
454 ret_stuff.v2 = 0;
455 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_SYSCTL_IOBRICK_MODULE_GET, nasid, 0, 0, 0, 0, 0, 0);
457 /* result is in 'v0' */
458 *result = (int)ret_stuff.v0;
460 return ret_stuff.status;
464 * ia64_sn_pod_mode - call the SN_SAL_POD_MODE function
466 * SN_SAL_POD_MODE actually takes an argument, but it's always
467 * 0 when we call it from the kernel, so we don't have to expose
468 * it to the caller.
470 static inline u64
471 ia64_sn_pod_mode(void)
473 struct ia64_sal_retval isrv;
474 SAL_CALL(isrv, SN_SAL_POD_MODE, 0, 0, 0, 0, 0, 0, 0);
475 if (isrv.status)
476 return 0;
477 return isrv.v0;
481 * ia64_sn_probe_mem - read from memory safely
482 * @addr: address to probe
483 * @size: number bytes to read (1,2,4,8)
484 * @data_ptr: address to store value read by probe (-1 returned if probe fails)
486 * Call into the SAL to do a memory read. If the read generates a machine
487 * check, this routine will recover gracefully and return -1 to the caller.
488 * @addr is usually a kernel virtual address in uncached space (i.e. the
489 * address starts with 0xc), but if called in physical mode, @addr should
490 * be a physical address.
492 * Return values:
493 * 0 - probe successful
494 * 1 - probe failed (generated MCA)
495 * 2 - Bad arg
496 * <0 - PAL error
498 static inline u64
499 ia64_sn_probe_mem(long addr, long size, void *data_ptr)
501 struct ia64_sal_retval isrv;
503 SAL_CALL(isrv, SN_SAL_PROBE, addr, size, 0, 0, 0, 0, 0);
505 if (data_ptr) {
506 switch (size) {
507 case 1:
508 *((u8*)data_ptr) = (u8)isrv.v0;
509 break;
510 case 2:
511 *((u16*)data_ptr) = (u16)isrv.v0;
512 break;
513 case 4:
514 *((u32*)data_ptr) = (u32)isrv.v0;
515 break;
516 case 8:
517 *((u64*)data_ptr) = (u64)isrv.v0;
518 break;
519 default:
520 isrv.status = 2;
523 return isrv.status;
527 * Retrieve the system serial number as an ASCII string.
529 static inline u64
530 ia64_sn_sys_serial_get(char *buf)
532 struct ia64_sal_retval ret_stuff;
533 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_SYS_SERIAL_GET, buf, 0, 0, 0, 0, 0, 0);
534 return ret_stuff.status;
537 extern char sn_system_serial_number_string[];
538 extern u64 sn_partition_serial_number;
540 static inline char *
541 sn_system_serial_number(void) {
542 if (sn_system_serial_number_string[0]) {
543 return(sn_system_serial_number_string);
544 } else {
545 ia64_sn_sys_serial_get(sn_system_serial_number_string);
546 return(sn_system_serial_number_string);
552 * Returns a unique id number for this system and partition (suitable for
553 * use with license managers), based in part on the system serial number.
555 static inline u64
556 ia64_sn_partition_serial_get(void)
558 struct ia64_sal_retval ret_stuff;
559 SAL_CALL(ret_stuff, SN_SAL_PARTITION_SERIAL_GET, 0, 0, 0, 0, 0, 0, 0);
560 if (ret_stuff.status != 0)
561 return 0;
562 return ret_stuff.v0;
565 static inline u64
566 sn_partition_serial_number_val(void) {
567 if (sn_partition_serial_number) {
568 return(sn_partition_serial_number);
569 } else {
570 return(sn_partition_serial_number = ia64_sn_partition_serial_get());
575 * Returns the partition id of the nasid passed in as an argument,
576 * or INVALID_PARTID if the partition id cannot be retrieved.
578 static inline partid_t
579 ia64_sn_sysctl_partition_get(nasid_t nasid)
581 struct ia64_sal_retval ret_stuff;
582 SAL_CALL(ret_stuff, SN_SAL_SYSCTL_PARTITION_GET, nasid,
583 0, 0, 0, 0, 0, 0);
584 if (ret_stuff.status != 0)
585 return INVALID_PARTID;
586 return ((partid_t)ret_stuff.v0);
590 * Returns the partition id of the current processor.
593 extern partid_t sn_partid;
595 static inline partid_t
596 sn_local_partid(void) {
597 if (sn_partid < 0) {
598 return (sn_partid = ia64_sn_sysctl_partition_get(cpuid_to_nasid(smp_processor_id())));
599 } else {
600 return sn_partid;
605 * Register or unregister a physical address range being referenced across
606 * a partition boundary for which certain SAL errors should be scanned for,
607 * cleaned up and ignored. This is of value for kernel partitioning code only.
608 * Values for the operation argument:
609 * 1 = register this address range with SAL
610 * 0 = unregister this address range with SAL
612 * SAL maintains a reference count on an address range in case it is registered
613 * multiple times.
615 * On success, returns the reference count of the address range after the SAL
616 * call has performed the current registration/unregistration. Returns a
617 * negative value if an error occurred.
619 static inline int
620 sn_register_xp_addr_region(u64 paddr, u64 len, int operation)
622 struct ia64_sal_retval ret_stuff;
623 SAL_CALL(ret_stuff, SN_SAL_XP_ADDR_REGION, paddr, len, (u64)operation,
624 0, 0, 0, 0);
625 return ret_stuff.status;
629 * Register or unregister an instruction range for which SAL errors should
630 * be ignored. If an error occurs while in the registered range, SAL jumps
631 * to return_addr after ignoring the error. Values for the operation argument:
632 * 1 = register this instruction range with SAL
633 * 0 = unregister this instruction range with SAL
635 * Returns 0 on success, or a negative value if an error occurred.
637 static inline int
638 sn_register_nofault_code(u64 start_addr, u64 end_addr, u64 return_addr,
639 int virtual, int operation)
641 struct ia64_sal_retval ret_stuff;
642 u64 call;
643 if (virtual) {
644 call = SN_SAL_NO_FAULT_ZONE_VIRTUAL;
645 } else {
646 call = SN_SAL_NO_FAULT_ZONE_PHYSICAL;
648 SAL_CALL(ret_stuff, call, start_addr, end_addr, return_addr, (u64)1,
649 0, 0, 0);
650 return ret_stuff.status;
654 * Change or query the coherence domain for this partition. Each cpu-based
655 * nasid is represented by a bit in an array of 64-bit words:
656 * 0 = not in this partition's coherency domain
657 * 1 = in this partition's coherency domain
659 * It is not possible for the local system's nasids to be removed from
660 * the coherency domain. Purpose of the domain arguments:
661 * new_domain = set the coherence domain to the given nasids
662 * old_domain = return the current coherence domain
664 * Returns 0 on success, or a negative value if an error occurred.
666 static inline int
667 sn_change_coherence(u64 *new_domain, u64 *old_domain)
669 struct ia64_sal_retval ret_stuff;
670 SAL_CALL(ret_stuff, SN_SAL_COHERENCE, new_domain, old_domain, 0, 0,
671 0, 0, 0);
672 return ret_stuff.status;
676 * Change memory access protections for a physical address range.
677 * nasid_array is not used on Altix, but may be in future architectures.
678 * Available memory protection access classes are defined after the function.
680 static inline int
681 sn_change_memprotect(u64 paddr, u64 len, u64 perms, u64 *nasid_array)
683 struct ia64_sal_retval ret_stuff;
684 int cnodeid;
685 unsigned long irq_flags;
687 cnodeid = nasid_to_cnodeid(get_node_number(paddr));
688 // spin_lock(&NODEPDA(cnodeid)->bist_lock);
689 local_irq_save(irq_flags);
690 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_MEMPROTECT, paddr, len, nasid_array,
691 perms, 0, 0, 0);
692 local_irq_restore(irq_flags);
693 // spin_unlock(&NODEPDA(cnodeid)->bist_lock);
694 return ret_stuff.status;
696 #define SN_MEMPROT_ACCESS_CLASS_0 0x14a080
697 #define SN_MEMPROT_ACCESS_CLASS_1 0x2520c2
698 #define SN_MEMPROT_ACCESS_CLASS_2 0x14a1ca
699 #define SN_MEMPROT_ACCESS_CLASS_3 0x14a290
700 #define SN_MEMPROT_ACCESS_CLASS_6 0x084080
701 #define SN_MEMPROT_ACCESS_CLASS_7 0x021080
704 * Turns off system power.
706 static inline void
707 ia64_sn_power_down(void)
709 struct ia64_sal_retval ret_stuff;
710 SAL_CALL(ret_stuff, SN_SAL_SYSTEM_POWER_DOWN, 0, 0, 0, 0, 0, 0, 0);
711 while(1);
712 /* never returns */
716 * ia64_sn_fru_capture - tell the system controller to capture hw state
718 * This routine will call the SAL which will tell the system controller(s)
719 * to capture hw mmr information from each SHub in the system.
721 static inline u64
722 ia64_sn_fru_capture(void)
724 struct ia64_sal_retval isrv;
725 SAL_CALL(isrv, SN_SAL_SYSCTL_FRU_CAPTURE, 0, 0, 0, 0, 0, 0, 0);
726 if (isrv.status)
727 return 0;
728 return isrv.v0;
732 * Performs an operation on a PCI bus or slot -- power up, power down
733 * or reset.
735 static inline u64
736 ia64_sn_sysctl_iobrick_pci_op(nasid_t n, u64 connection_type,
737 u64 bus, char slot,
738 u64 action)
740 struct ia64_sal_retval rv = {0, 0, 0, 0};
742 SAL_CALL_NOLOCK(rv, SN_SAL_SYSCTL_IOBRICK_PCI_OP, connection_type, n, action,
743 bus, (u64) slot, 0, 0);
744 if (rv.status)
745 return rv.v0;
746 return 0;
751 * Open a subchannel for sending arbitrary data to the system
752 * controller network via the system controller device associated with
753 * 'nasid'. Return the subchannel number or a negative error code.
755 static inline int
756 ia64_sn_irtr_open(nasid_t nasid)
758 struct ia64_sal_retval rv;
759 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_OPEN, nasid,
760 0, 0, 0, 0, 0);
761 return (int) rv.v0;
765 * Close system controller subchannel 'subch' previously opened on 'nasid'.
767 static inline int
768 ia64_sn_irtr_close(nasid_t nasid, int subch)
770 struct ia64_sal_retval rv;
771 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_CLOSE,
772 (u64) nasid, (u64) subch, 0, 0, 0, 0);
773 return (int) rv.status;
777 * Read data from system controller associated with 'nasid' on
778 * subchannel 'subch'. The buffer to be filled is pointed to by
779 * 'buf', and its capacity is in the integer pointed to by 'len'. The
780 * referent of 'len' is set to the number of bytes read by the SAL
781 * call. The return value is either SALRET_OK (for bytes read) or
782 * SALRET_ERROR (for error or "no data available").
784 static inline int
785 ia64_sn_irtr_recv(nasid_t nasid, int subch, char *buf, int *len)
787 struct ia64_sal_retval rv;
788 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_RECV,
789 (u64) nasid, (u64) subch, (u64) buf, (u64) len,
790 0, 0);
791 return (int) rv.status;
795 * Write data to the system controller network via the system
796 * controller associated with 'nasid' on suchannel 'subch'. The
797 * buffer to be written out is pointed to by 'buf', and 'len' is the
798 * number of bytes to be written. The return value is either the
799 * number of bytes written (which could be zero) or a negative error
800 * code.
802 static inline int
803 ia64_sn_irtr_send(nasid_t nasid, int subch, char *buf, int len)
805 struct ia64_sal_retval rv;
806 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_SEND,
807 (u64) nasid, (u64) subch, (u64) buf, (u64) len,
808 0, 0);
809 return (int) rv.v0;
813 * Check whether any interrupts are pending for the system controller
814 * associated with 'nasid' and its subchannel 'subch'. The return
815 * value is a mask of pending interrupts (SAL_IROUTER_INTR_XMIT and/or
816 * SAL_IROUTER_INTR_RECV).
818 static inline int
819 ia64_sn_irtr_intr(nasid_t nasid, int subch)
821 struct ia64_sal_retval rv;
822 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_STATUS,
823 (u64) nasid, (u64) subch, 0, 0, 0, 0);
824 return (int) rv.v0;
828 * Enable the interrupt indicated by the intr parameter (either
829 * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
831 static inline int
832 ia64_sn_irtr_intr_enable(nasid_t nasid, int subch, u64 intr)
834 struct ia64_sal_retval rv;
835 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_ON,
836 (u64) nasid, (u64) subch, intr, 0, 0, 0);
837 return (int) rv.v0;
841 * Disable the interrupt indicated by the intr parameter (either
842 * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
844 static inline int
845 ia64_sn_irtr_intr_disable(nasid_t nasid, int subch, u64 intr)
847 struct ia64_sal_retval rv;
848 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INTR_OFF,
849 (u64) nasid, (u64) subch, intr, 0, 0, 0);
850 return (int) rv.v0;
854 * ia64_sn_get_fit_compt - read a FIT entry from the PROM header
855 * @nasid: NASID of node to read
856 * @index: FIT entry index to be retrieved (0..n)
857 * @fitentry: 16 byte buffer where FIT entry will be stored.
858 * @banbuf: optional buffer for retrieving banner
859 * @banlen: length of banner buffer
861 * Access to the physical PROM chips needs to be serialized since reads and
862 * writes can't occur at the same time, so we need to call into the SAL when
863 * we want to look at the FIT entries on the chips.
865 * Returns:
866 * %SALRET_OK if ok
867 * %SALRET_INVALID_ARG if index too big
868 * %SALRET_NOT_IMPLEMENTED if running on older PROM
869 * ??? if nasid invalid OR banner buffer not large enough
871 static inline int
872 ia64_sn_get_fit_compt(u64 nasid, u64 index, void *fitentry, void *banbuf,
873 u64 banlen)
875 struct ia64_sal_retval rv;
876 SAL_CALL_NOLOCK(rv, SN_SAL_GET_FIT_COMPT, nasid, index, fitentry,
877 banbuf, banlen, 0, 0);
878 return (int) rv.status;
882 * Initialize the SAL components of the system controller
883 * communication driver; specifically pass in a sizable buffer that
884 * can be used for allocation of subchannel queues as new subchannels
885 * are opened. "buf" points to the buffer, and "len" specifies its
886 * length.
888 static inline int
889 ia64_sn_irtr_init(nasid_t nasid, void *buf, int len)
891 struct ia64_sal_retval rv;
892 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INIT,
893 (u64) nasid, (u64) buf, (u64) len, 0, 0, 0);
894 return (int) rv.status;
898 * Returns the nasid, subnode & slice corresponding to a SAPIC ID
900 * In:
901 * arg0 - SN_SAL_GET_SAPIC_INFO
902 * arg1 - sapicid (lid >> 16)
903 * Out:
904 * v0 - nasid
905 * v1 - subnode
906 * v2 - slice
908 static inline u64
909 ia64_sn_get_sapic_info(int sapicid, int *nasid, int *subnode, int *slice)
911 struct ia64_sal_retval ret_stuff;
913 ret_stuff.status = 0;
914 ret_stuff.v0 = 0;
915 ret_stuff.v1 = 0;
916 ret_stuff.v2 = 0;
917 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SAPIC_INFO, sapicid, 0, 0, 0, 0, 0, 0);
919 /***** BEGIN HACK - temp til old proms no longer supported ********/
920 if (ret_stuff.status == SALRET_NOT_IMPLEMENTED) {
921 if (nasid) *nasid = sapicid & 0xfff;
922 if (subnode) *subnode = (sapicid >> 13) & 1;
923 if (slice) *slice = (sapicid >> 12) & 3;
924 return 0;
926 /***** END HACK *******/
928 if (ret_stuff.status < 0)
929 return ret_stuff.status;
931 if (nasid) *nasid = (int) ret_stuff.v0;
932 if (subnode) *subnode = (int) ret_stuff.v1;
933 if (slice) *slice = (int) ret_stuff.v2;
934 return 0;
938 * Returns information about the HUB/SHUB.
939 * In:
940 * arg0 - SN_SAL_GET_SN_INFO
941 * arg1 - 0 (other values reserved for future use)
942 * Out:
943 * v0
944 * [7:0] - shub type (0=shub1, 1=shub2)
945 * [15:8] - Log2 max number of nodes in entire system (includes
946 * C-bricks, I-bricks, etc)
947 * [23:16] - Log2 of nodes per sharing domain
948 * [31:24] - partition ID
949 * [39:32] - coherency_id
950 * [47:40] - regionsize
951 * v1
952 * [15:0] - nasid mask (ex., 0x7ff for 11 bit nasid)
953 * [23:15] - bit position of low nasid bit
955 static inline u64
956 ia64_sn_get_sn_info(int fc, u8 *shubtype, u16 *nasid_bitmask, u8 *nasid_shift,
957 u8 *systemsize, u8 *sharing_domain_size, u8 *partid, u8 *coher, u8 *reg)
959 struct ia64_sal_retval ret_stuff;
961 ret_stuff.status = 0;
962 ret_stuff.v0 = 0;
963 ret_stuff.v1 = 0;
964 ret_stuff.v2 = 0;
965 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SN_INFO, fc, 0, 0, 0, 0, 0, 0);
967 /***** BEGIN HACK - temp til old proms no longer supported ********/
968 if (ret_stuff.status == SALRET_NOT_IMPLEMENTED) {
969 int nasid = get_sapicid() & 0xfff;;
970 #define SH_SHUB_ID_NODES_PER_BIT_MASK 0x001f000000000000UL
971 #define SH_SHUB_ID_NODES_PER_BIT_SHFT 48
972 if (shubtype) *shubtype = 0;
973 if (nasid_bitmask) *nasid_bitmask = 0x7ff;
974 if (nasid_shift) *nasid_shift = 38;
975 if (systemsize) *systemsize = 11;
976 if (sharing_domain_size) *sharing_domain_size = 9;
977 if (partid) *partid = ia64_sn_sysctl_partition_get(nasid);
978 if (coher) *coher = nasid >> 9;
979 if (reg) *reg = (HUB_L((u64 *) LOCAL_MMR_ADDR(SH1_SHUB_ID)) & SH_SHUB_ID_NODES_PER_BIT_MASK) >>
980 SH_SHUB_ID_NODES_PER_BIT_SHFT;
981 return 0;
983 /***** END HACK *******/
985 if (ret_stuff.status < 0)
986 return ret_stuff.status;
988 if (shubtype) *shubtype = ret_stuff.v0 & 0xff;
989 if (systemsize) *systemsize = (ret_stuff.v0 >> 8) & 0xff;
990 if (sharing_domain_size) *sharing_domain_size = (ret_stuff.v0 >> 16) & 0xff;
991 if (partid) *partid = (ret_stuff.v0 >> 24) & 0xff;
992 if (coher) *coher = (ret_stuff.v0 >> 32) & 0xff;
993 if (reg) *reg = (ret_stuff.v0 >> 40) & 0xff;
994 if (nasid_bitmask) *nasid_bitmask = (ret_stuff.v1 & 0xffff);
995 if (nasid_shift) *nasid_shift = (ret_stuff.v1 >> 16) & 0xff;
996 return 0;
1000 * This is the access point to the Altix PROM hardware performance
1001 * and status monitoring interface. For info on using this, see
1002 * include/asm-ia64/sn/sn2/sn_hwperf.h
1004 static inline int
1005 ia64_sn_hwperf_op(nasid_t nasid, u64 opcode, u64 a0, u64 a1, u64 a2,
1006 u64 a3, u64 a4, int *v0)
1008 struct ia64_sal_retval rv;
1009 SAL_CALL_NOLOCK(rv, SN_SAL_HWPERF_OP, (u64)nasid,
1010 opcode, a0, a1, a2, a3, a4);
1011 if (v0)
1012 *v0 = (int) rv.v0;
1013 return (int) rv.status;
1016 static inline int
1017 ia64_sn_ioif_get_pci_topology(u64 rack, u64 bay, u64 slot, u64 slab,
1018 char *buf, u64 len)
1020 struct ia64_sal_retval rv;
1021 SAL_CALL_NOLOCK(rv, SN_SAL_IOIF_GET_PCI_TOPOLOGY,
1022 rack, bay, slot, slab, buf, len, 0);
1023 return (int) rv.status;
1027 * BTE error recovery is implemented in SAL
1029 static inline int
1030 ia64_sn_bte_recovery(nasid_t nasid)
1032 struct ia64_sal_retval rv;
1034 rv.status = 0;
1035 SAL_CALL_NOLOCK(rv, SN_SAL_BTE_RECOVER, 0, 0, 0, 0, 0, 0, 0);
1036 if (rv.status == SALRET_NOT_IMPLEMENTED)
1037 return 0;
1038 return (int) rv.status;
1041 #endif /* _ASM_IA64_SN_SN_SAL_H */