blob: 410d356b40dadf9e61bbd1a2cfe1391471302498 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_IA64_SN_SN_SAL_H
2#define _ASM_IA64_SN_SN_SAL_H
3
4/*
5 * System Abstraction Layer definitions for IA64
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 *
11 * Copyright (c) 2000-2004 Silicon Graphics, Inc. All rights reserved.
12 */
13
14
15#include <linux/config.h>
16#include <asm/sal.h>
17#include <asm/sn/sn_cpuid.h>
18#include <asm/sn/arch.h>
19#include <asm/sn/geo.h>
20#include <asm/sn/nodepda.h>
21#include <asm/sn/shub_mmr.h>
22
23// SGI Specific Calls
24#define SN_SAL_POD_MODE 0x02000001
25#define SN_SAL_SYSTEM_RESET 0x02000002
26#define SN_SAL_PROBE 0x02000003
27#define SN_SAL_GET_MASTER_NASID 0x02000004
28#define SN_SAL_GET_KLCONFIG_ADDR 0x02000005
29#define SN_SAL_LOG_CE 0x02000006
30#define SN_SAL_REGISTER_CE 0x02000007
31#define SN_SAL_GET_PARTITION_ADDR 0x02000009
32#define SN_SAL_XP_ADDR_REGION 0x0200000f
33#define SN_SAL_NO_FAULT_ZONE_VIRTUAL 0x02000010
34#define SN_SAL_NO_FAULT_ZONE_PHYSICAL 0x02000011
35#define SN_SAL_PRINT_ERROR 0x02000012
36#define SN_SAL_SET_ERROR_HANDLING_FEATURES 0x0200001a // reentrant
37#define SN_SAL_GET_FIT_COMPT 0x0200001b // reentrant
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define SN_SAL_GET_SAPIC_INFO 0x0200001d
Jack Steinerbf1cf98f2005-04-25 11:42:39 -070039#define SN_SAL_GET_SN_INFO 0x0200001e
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define SN_SAL_CONSOLE_PUTC 0x02000021
41#define SN_SAL_CONSOLE_GETC 0x02000022
42#define SN_SAL_CONSOLE_PUTS 0x02000023
43#define SN_SAL_CONSOLE_GETS 0x02000024
44#define SN_SAL_CONSOLE_GETS_TIMEOUT 0x02000025
45#define SN_SAL_CONSOLE_POLL 0x02000026
46#define SN_SAL_CONSOLE_INTR 0x02000027
47#define SN_SAL_CONSOLE_PUTB 0x02000028
48#define SN_SAL_CONSOLE_XMIT_CHARS 0x0200002a
49#define SN_SAL_CONSOLE_READC 0x0200002b
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_IOIF_INTERRUPT 0x0200004a
68#define SN_SAL_HWPERF_OP 0x02000050 // lock
69#define SN_SAL_IOIF_ERROR_INTERRUPT 0x02000051
70
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
Mark Goodwin4a5c13c2005-04-25 13:04:22 -070077#define SN_SAL_IOIF_GET_PCI_TOPOLOGY 0x02000059
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79#define SN_SAL_HUB_ERROR_INTERRUPT 0x02000060
80
81
82/*
83 * Service-specific constants
84 */
85
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 */
94
95/* interrupt handling */
96#define SAL_INTR_ALLOC 1
97#define SAL_INTR_FREE 2
98
99/*
100 * IRouter (i.e. generalized system controller) operations
101 */
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
108 */
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 */
112
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
116
117
118/*
119 * SAL Error Codes
120 */
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)
126
127
128/**
129 * sn_sal_rev_major - get the major SGI SAL revision number
130 *
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().
134 */
135static inline int
136sn_sal_rev_major(void)
137{
138 struct ia64_sal_systab *systab = efi.sal_systab;
139
140 return (int)systab->sal_b_rev_major;
141}
142
143/**
144 * sn_sal_rev_minor - get the minor SGI SAL revision number
145 *
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().
149 */
150static inline int
151sn_sal_rev_minor(void)
152{
153 struct ia64_sal_systab *systab = efi.sal_systab;
154
155 return (int)systab->sal_b_rev_minor;
156}
157
158/*
159 * Specify the minimum PROM revsion required for this kernel.
160 * Note that they're stored in hex format...
161 */
162#define SN_SAL_MIN_MAJOR 0x4 /* SN2 kernels need at least PROM 4.0 */
163#define SN_SAL_MIN_MINOR 0x0
164
165/*
166 * Returns the master console nasid, if the call fails, return an illegal
167 * value.
168 */
169static inline u64
170ia64_sn_get_console_nasid(void)
171{
172 struct ia64_sal_retval ret_stuff;
173
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);
179
180 if (ret_stuff.status < 0)
181 return ret_stuff.status;
182
183 /* Master console nasid is in 'v0' */
184 return ret_stuff.v0;
185}
186
187/*
188 * Returns the master baseio nasid, if the call fails, return an illegal
189 * value.
190 */
191static inline u64
192ia64_sn_get_master_baseio_nasid(void)
193{
194 struct ia64_sal_retval ret_stuff;
195
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);
201
202 if (ret_stuff.status < 0)
203 return ret_stuff.status;
204
205 /* Master baseio nasid is in 'v0' */
206 return ret_stuff.v0;
207}
208
209static inline char *
210ia64_sn_get_klconfig_addr(nasid_t nasid)
211{
212 struct ia64_sal_retval ret_stuff;
213 int cnodeid;
214
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);
221
222 /*
223 * We should panic if a valid cnode nasid does not produce
224 * a klconfig address.
225 */
226 if (ret_stuff.status != 0) {
227 panic("ia64_sn_get_klconfig_addr: Returned error %lx\n", ret_stuff.status);
228 }
229 return ret_stuff.v0 ? __va(ret_stuff.v0) : NULL;
230}
231
232/*
233 * Returns the next console character.
234 */
235static inline u64
236ia64_sn_console_getc(int *ch)
237{
238 struct ia64_sal_retval ret_stuff;
239
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);
245
246 /* character is in 'v0' */
247 *ch = (int)ret_stuff.v0;
248
249 return ret_stuff.status;
250}
251
252/*
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.
256 */
257static inline u64
258ia64_sn_console_readc(void)
259{
260 struct ia64_sal_retval ret_stuff;
261
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);
267
268 /* character is in 'v0' */
269 return ret_stuff.v0;
270}
271
272/*
273 * Sends the given character to the console.
274 */
275static inline u64
276ia64_sn_console_putc(char ch)
277{
278 struct ia64_sal_retval ret_stuff;
279
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);
285
286 return ret_stuff.status;
287}
288
289/*
290 * Sends the given buffer to the console.
291 */
292static inline u64
293ia64_sn_console_putb(const char *buf, int len)
294{
295 struct ia64_sal_retval ret_stuff;
296
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);
302
303 if ( ret_stuff.status == 0 ) {
304 return ret_stuff.v0;
305 }
306 return (u64)0;
307}
308
309/*
310 * Print a platform error record
311 */
312static inline u64
313ia64_sn_plat_specific_err_print(int (*hook)(const char*, ...), char *rec)
314{
315 struct ia64_sal_retval ret_stuff;
316
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);
322
323 return ret_stuff.status;
324}
325
326/*
327 * Check for Platform errors
328 */
329static inline u64
330ia64_sn_plat_cpei_handler(void)
331{
332 struct ia64_sal_retval ret_stuff;
333
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);
339
340 return ret_stuff.status;
341}
342
343/*
344 * Checks for console input.
345 */
346static inline u64
347ia64_sn_console_check(int *result)
348{
349 struct ia64_sal_retval ret_stuff;
350
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);
356
357 /* result is in 'v0' */
358 *result = (int)ret_stuff.v0;
359
360 return ret_stuff.status;
361}
362
363/*
364 * Checks console interrupt status
365 */
366static inline u64
367ia64_sn_console_intr_status(void)
368{
369 struct ia64_sal_retval ret_stuff;
370
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);
378
379 if (ret_stuff.status == 0) {
380 return ret_stuff.v0;
381 }
382
383 return 0;
384}
385
386/*
387 * Enable an interrupt on the SAL console device.
388 */
389static inline void
390ia64_sn_console_intr_enable(uint64_t intr)
391{
392 struct ia64_sal_retval ret_stuff;
393
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);
401}
402
403/*
404 * Disable an interrupt on the SAL console device.
405 */
406static inline void
407ia64_sn_console_intr_disable(uint64_t intr)
408{
409 struct ia64_sal_retval ret_stuff;
410
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);
418}
419
420/*
421 * Sends a character buffer to the console asynchronously.
422 */
423static inline u64
424ia64_sn_console_xmit_chars(char *buf, int len)
425{
426 struct ia64_sal_retval ret_stuff;
427
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);
435
436 if (ret_stuff.status == 0) {
437 return ret_stuff.v0;
438 }
439
440 return 0;
441}
442
443/*
444 * Returns the iobrick module Id
445 */
446static inline u64
447ia64_sn_sysctl_iobrick_module_get(nasid_t nasid, int *result)
448{
449 struct ia64_sal_retval ret_stuff;
450
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);
456
457 /* result is in 'v0' */
458 *result = (int)ret_stuff.v0;
459
460 return ret_stuff.status;
461}
462
463/**
464 * ia64_sn_pod_mode - call the SN_SAL_POD_MODE function
465 *
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.
469 */
470static inline u64
471ia64_sn_pod_mode(void)
472{
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;
478}
479
480/**
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)
485 *
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.
491 *
492 * Return values:
493 * 0 - probe successful
494 * 1 - probe failed (generated MCA)
495 * 2 - Bad arg
496 * <0 - PAL error
497 */
498static inline u64
499ia64_sn_probe_mem(long addr, long size, void *data_ptr)
500{
501 struct ia64_sal_retval isrv;
502
503 SAL_CALL(isrv, SN_SAL_PROBE, addr, size, 0, 0, 0, 0, 0);
504
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;
521 }
522 }
523 return isrv.status;
524}
525
526/*
527 * Retrieve the system serial number as an ASCII string.
528 */
529static inline u64
530ia64_sn_sys_serial_get(char *buf)
531{
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;
535}
536
537extern char sn_system_serial_number_string[];
538extern u64 sn_partition_serial_number;
539
540static inline char *
541sn_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);
547 }
548}
549
550
551/*
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.
554 */
555static inline u64
556ia64_sn_partition_serial_get(void)
557{
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;
563}
564
565static inline u64
566sn_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());
571 }
572}
573
574/*
575 * Returns the partition id of the nasid passed in as an argument,
576 * or INVALID_PARTID if the partition id cannot be retrieved.
577 */
578static inline partid_t
579ia64_sn_sysctl_partition_get(nasid_t nasid)
580{
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);
587}
588
589/*
590 * Returns the partition id of the current processor.
591 */
592
593extern partid_t sn_partid;
594
595static inline partid_t
596sn_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;
601 }
602}
603
604/*
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
611 *
612 * SAL maintains a reference count on an address range in case it is registered
613 * multiple times.
614 *
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.
618 */
619static inline int
620sn_register_xp_addr_region(u64 paddr, u64 len, int operation)
621{
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;
626}
627
628/*
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
634 *
635 * Returns 0 on success, or a negative value if an error occurred.
636 */
637static inline int
638sn_register_nofault_code(u64 start_addr, u64 end_addr, u64 return_addr,
639 int virtual, int operation)
640{
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;
647 }
648 SAL_CALL(ret_stuff, call, start_addr, end_addr, return_addr, (u64)1,
649 0, 0, 0);
650 return ret_stuff.status;
651}
652
653/*
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
658 *
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
663 *
664 * Returns 0 on success, or a negative value if an error occurred.
665 */
666static inline int
667sn_change_coherence(u64 *new_domain, u64 *old_domain)
668{
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;
673}
674
675/*
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.
679 */
680static inline int
681sn_change_memprotect(u64 paddr, u64 len, u64 perms, u64 *nasid_array)
682{
683 struct ia64_sal_retval ret_stuff;
684 int cnodeid;
685 unsigned long irq_flags;
686
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;
695}
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
702
703/*
704 * Turns off system power.
705 */
706static inline void
707ia64_sn_power_down(void)
708{
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 */
713}
714
715/**
716 * ia64_sn_fru_capture - tell the system controller to capture hw state
717 *
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.
720 */
721static inline u64
722ia64_sn_fru_capture(void)
723{
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;
729}
730
731/*
732 * Performs an operation on a PCI bus or slot -- power up, power down
733 * or reset.
734 */
735static inline u64
736ia64_sn_sysctl_iobrick_pci_op(nasid_t n, u64 connection_type,
737 u64 bus, char slot,
738 u64 action)
739{
740 struct ia64_sal_retval rv = {0, 0, 0, 0};
741
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;
747}
748
749
750/*
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.
754 */
755static inline int
756ia64_sn_irtr_open(nasid_t nasid)
757{
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;
762}
763
764/*
765 * Close system controller subchannel 'subch' previously opened on 'nasid'.
766 */
767static inline int
768ia64_sn_irtr_close(nasid_t nasid, int subch)
769{
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;
774}
775
776/*
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").
783 */
784static inline int
785ia64_sn_irtr_recv(nasid_t nasid, int subch, char *buf, int *len)
786{
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;
792}
793
794/*
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.
801 */
802static inline int
803ia64_sn_irtr_send(nasid_t nasid, int subch, char *buf, int len)
804{
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;
810}
811
812/*
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).
817 */
818static inline int
819ia64_sn_irtr_intr(nasid_t nasid, int subch)
820{
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;
825}
826
827/*
828 * Enable the interrupt indicated by the intr parameter (either
829 * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
830 */
831static inline int
832ia64_sn_irtr_intr_enable(nasid_t nasid, int subch, u64 intr)
833{
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;
838}
839
840/*
841 * Disable the interrupt indicated by the intr parameter (either
842 * SAL_IROUTER_INTR_XMIT or SAL_IROUTER_INTR_RECV).
843 */
844static inline int
845ia64_sn_irtr_intr_disable(nasid_t nasid, int subch, u64 intr)
846{
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;
851}
852
853/**
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
860 *
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.
864 *
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
870 */
871static inline int
872ia64_sn_get_fit_compt(u64 nasid, u64 index, void *fitentry, void *banbuf,
873 u64 banlen)
874{
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;
879}
880
881/*
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.
887 */
888static inline int
889ia64_sn_irtr_init(nasid_t nasid, void *buf, int len)
890{
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;
895}
896
897/*
898 * Returns the nasid, subnode & slice corresponding to a SAPIC ID
899 *
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
907 */
908static inline u64
909ia64_sn_get_sapic_info(int sapicid, int *nasid, int *subnode, int *slice)
910{
911 struct ia64_sal_retval ret_stuff;
912
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);
918
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;
925 }
926/***** END HACK *******/
927
928 if (ret_stuff.status < 0)
929 return ret_stuff.status;
930
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;
935}
936
937/*
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
954 */
955static inline u64
956ia64_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)
958{
959 struct ia64_sal_retval ret_stuff;
960
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);
966
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;
982 }
983/***** END HACK *******/
984
985 if (ret_stuff.status < 0)
986 return ret_stuff.status;
987
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;
997}
998
999/*
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
1003 */
1004static inline int
1005ia64_sn_hwperf_op(nasid_t nasid, u64 opcode, u64 a0, u64 a1, u64 a2,
1006 u64 a3, u64 a4, int *v0)
1007{
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;
1014}
1015
Mark Goodwin4a5c13c2005-04-25 13:04:22 -07001016static inline int
1017ia64_sn_ioif_get_pci_topology(u64 rack, u64 bay, u64 slot, u64 slab,
1018 char *buf, u64 len)
1019{
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;
1024}
1025
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026#endif /* _ASM_IA64_SN_SN_SAL_H */