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