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