blob: 5ad855db8464511733595f866664485378eb6439 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define SN_SAL_SYSTEM_POWER_DOWN 0x0200003b
59#define SN_SAL_GET_MASTER_BASEIO_NASID 0x0200003c
60#define SN_SAL_COHERENCE 0x0200003d
61#define SN_SAL_MEMPROTECT 0x0200003e
62#define SN_SAL_SYSCTL_FRU_CAPTURE 0x0200003f
63
64#define SN_SAL_SYSCTL_IOBRICK_PCI_OP 0x02000042 // reentrant
65#define SN_SAL_IROUTER_OP 0x02000043
Greg Howard67639de2005-04-25 13:28:52 -070066#define SN_SAL_SYSCTL_EVENT 0x02000044
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#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
77
78#define SN_SAL_HUB_ERROR_INTERRUPT 0x02000060
Russ Anderson93a07d02005-04-25 13:19:52 -070079#define SN_SAL_BTE_RECOVER 0x02000061
Mark Goodwinecc3c302005-08-16 00:50:00 -070080#define SN_SAL_RESERVED_DO_NOT_USE 0x02000062
81#define SN_SAL_IOIF_GET_PCI_TOPOLOGY 0x02000064
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Jack Steinera1cddb82005-08-31 08:05:00 -070083#define SN_SAL_GET_PROM_FEATURE_SET 0x02000065
84#define SN_SAL_SET_OS_FEATURE_SET 0x02000066
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086/*
87 * Service-specific constants
88 */
89
90/* Console interrupt manipulation */
91 /* action codes */
92#define SAL_CONSOLE_INTR_OFF 0 /* turn the interrupt off */
93#define SAL_CONSOLE_INTR_ON 1 /* turn the interrupt on */
94#define SAL_CONSOLE_INTR_STATUS 2 /* retrieve the interrupt status */
95 /* interrupt specification & status return codes */
96#define SAL_CONSOLE_INTR_XMIT 1 /* output interrupt */
97#define SAL_CONSOLE_INTR_RECV 2 /* input interrupt */
98
99/* interrupt handling */
100#define SAL_INTR_ALLOC 1
101#define SAL_INTR_FREE 2
102
103/*
104 * IRouter (i.e. generalized system controller) operations
105 */
106#define SAL_IROUTER_OPEN 0 /* open a subchannel */
107#define SAL_IROUTER_CLOSE 1 /* close a subchannel */
108#define SAL_IROUTER_SEND 2 /* send part of an IRouter packet */
109#define SAL_IROUTER_RECV 3 /* receive part of an IRouter packet */
110#define SAL_IROUTER_INTR_STATUS 4 /* check the interrupt status for
111 * an open subchannel
112 */
113#define SAL_IROUTER_INTR_ON 5 /* enable an interrupt */
114#define SAL_IROUTER_INTR_OFF 6 /* disable an interrupt */
115#define SAL_IROUTER_INIT 7 /* initialize IRouter driver */
116
117/* IRouter interrupt mask bits */
118#define SAL_IROUTER_INTR_XMIT SAL_CONSOLE_INTR_XMIT
119#define SAL_IROUTER_INTR_RECV SAL_CONSOLE_INTR_RECV
120
Russ Anderson6872ec52005-05-16 15:30:00 -0700121/*
122 * Error Handling Features
123 */
Jack Steinera1cddb82005-08-31 08:05:00 -0700124#define SAL_ERR_FEAT_MCA_SLV_TO_OS_INIT_SLV 0x1 // obsolete
125#define SAL_ERR_FEAT_LOG_SBES 0x2 // obsolete
Russ Anderson6872ec52005-05-16 15:30:00 -0700126#define SAL_ERR_FEAT_MFR_OVERRIDE 0x4
127#define SAL_ERR_FEAT_SBE_THRESHOLD 0xffff0000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129/*
130 * SAL Error Codes
131 */
132#define SALRET_MORE_PASSES 1
133#define SALRET_OK 0
134#define SALRET_NOT_IMPLEMENTED (-1)
135#define SALRET_INVALID_ARG (-2)
136#define SALRET_ERROR (-3)
137
Jack Steiner71a5d022005-05-10 08:01:00 -0700138#define SN_SAL_FAKE_PROM 0x02009999
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140/**
Prarit Bhargava283c7f62005-07-06 15:29:13 -0700141 * sn_sal_revision - get the SGI SAL revision number
142 *
143 * The SGI PROM stores its version in the sal_[ab]_rev_(major|minor).
144 * This routine simply extracts the major and minor values and
145 * presents them in a u32 format.
146 *
147 * For example, version 4.05 would be represented at 0x0405.
148 */
149static inline u32
150sn_sal_rev(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
152 struct ia64_sal_systab *systab = efi.sal_systab;
153
Prarit Bhargava283c7f62005-07-06 15:29:13 -0700154 return (u32)(systab->sal_b_rev_major << 8 | systab->sal_b_rev_minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
156
157/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 * Returns the master console nasid, if the call fails, return an illegal
159 * value.
160 */
161static inline u64
162ia64_sn_get_console_nasid(void)
163{
164 struct ia64_sal_retval ret_stuff;
165
166 ret_stuff.status = 0;
167 ret_stuff.v0 = 0;
168 ret_stuff.v1 = 0;
169 ret_stuff.v2 = 0;
170 SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_NASID, 0, 0, 0, 0, 0, 0, 0);
171
172 if (ret_stuff.status < 0)
173 return ret_stuff.status;
174
175 /* Master console nasid is in 'v0' */
176 return ret_stuff.v0;
177}
178
179/*
180 * Returns the master baseio nasid, if the call fails, return an illegal
181 * value.
182 */
183static inline u64
184ia64_sn_get_master_baseio_nasid(void)
185{
186 struct ia64_sal_retval ret_stuff;
187
188 ret_stuff.status = 0;
189 ret_stuff.v0 = 0;
190 ret_stuff.v1 = 0;
191 ret_stuff.v2 = 0;
192 SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_BASEIO_NASID, 0, 0, 0, 0, 0, 0, 0);
193
194 if (ret_stuff.status < 0)
195 return ret_stuff.status;
196
197 /* Master baseio nasid is in 'v0' */
198 return ret_stuff.v0;
199}
200
Jack Steiner24ee0a62005-09-12 12:15:43 -0500201static inline void *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202ia64_sn_get_klconfig_addr(nasid_t nasid)
203{
204 struct ia64_sal_retval ret_stuff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 ret_stuff.status = 0;
207 ret_stuff.v0 = 0;
208 ret_stuff.v1 = 0;
209 ret_stuff.v2 = 0;
210 SAL_CALL(ret_stuff, SN_SAL_GET_KLCONFIG_ADDR, (u64)nasid, 0, 0, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 return ret_stuff.v0 ? __va(ret_stuff.v0) : NULL;
212}
213
214/*
215 * Returns the next console character.
216 */
217static inline u64
218ia64_sn_console_getc(int *ch)
219{
220 struct ia64_sal_retval ret_stuff;
221
222 ret_stuff.status = 0;
223 ret_stuff.v0 = 0;
224 ret_stuff.v1 = 0;
225 ret_stuff.v2 = 0;
226 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_GETC, 0, 0, 0, 0, 0, 0, 0);
227
228 /* character is in 'v0' */
229 *ch = (int)ret_stuff.v0;
230
231 return ret_stuff.status;
232}
233
234/*
235 * Read a character from the SAL console device, after a previous interrupt
236 * or poll operation has given us to know that a character is available
237 * to be read.
238 */
239static inline u64
240ia64_sn_console_readc(void)
241{
242 struct ia64_sal_retval ret_stuff;
243
244 ret_stuff.status = 0;
245 ret_stuff.v0 = 0;
246 ret_stuff.v1 = 0;
247 ret_stuff.v2 = 0;
248 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_READC, 0, 0, 0, 0, 0, 0, 0);
249
250 /* character is in 'v0' */
251 return ret_stuff.v0;
252}
253
254/*
255 * Sends the given character to the console.
256 */
257static inline u64
258ia64_sn_console_putc(char ch)
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_PUTC, (uint64_t)ch, 0, 0, 0, 0, 0, 0);
267
268 return ret_stuff.status;
269}
270
271/*
272 * Sends the given buffer to the console.
273 */
274static inline u64
275ia64_sn_console_putb(const char *buf, int len)
276{
277 struct ia64_sal_retval ret_stuff;
278
279 ret_stuff.status = 0;
280 ret_stuff.v0 = 0;
281 ret_stuff.v1 = 0;
282 ret_stuff.v2 = 0;
283 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_CONSOLE_PUTB, (uint64_t)buf, (uint64_t)len, 0, 0, 0, 0, 0);
284
285 if ( ret_stuff.status == 0 ) {
286 return ret_stuff.v0;
287 }
288 return (u64)0;
289}
290
291/*
292 * Print a platform error record
293 */
294static inline u64
295ia64_sn_plat_specific_err_print(int (*hook)(const char*, ...), char *rec)
296{
297 struct ia64_sal_retval ret_stuff;
298
299 ret_stuff.status = 0;
300 ret_stuff.v0 = 0;
301 ret_stuff.v1 = 0;
302 ret_stuff.v2 = 0;
303 SAL_CALL_REENTRANT(ret_stuff, SN_SAL_PRINT_ERROR, (uint64_t)hook, (uint64_t)rec, 0, 0, 0, 0, 0);
304
305 return ret_stuff.status;
306}
307
308/*
309 * Check for Platform errors
310 */
311static inline u64
312ia64_sn_plat_cpei_handler(void)
313{
314 struct ia64_sal_retval ret_stuff;
315
316 ret_stuff.status = 0;
317 ret_stuff.v0 = 0;
318 ret_stuff.v1 = 0;
319 ret_stuff.v2 = 0;
320 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_LOG_CE, 0, 0, 0, 0, 0, 0, 0);
321
322 return ret_stuff.status;
323}
324
325/*
Jack Steinera1cddb82005-08-31 08:05:00 -0700326 * Set Error Handling Features (Obsolete)
Russ Anderson6872ec52005-05-16 15:30:00 -0700327 */
328static inline u64
329ia64_sn_plat_set_error_handling_features(void)
330{
331 struct ia64_sal_retval ret_stuff;
332
333 ret_stuff.status = 0;
334 ret_stuff.v0 = 0;
335 ret_stuff.v1 = 0;
336 ret_stuff.v2 = 0;
337 SAL_CALL_REENTRANT(ret_stuff, SN_SAL_SET_ERROR_HANDLING_FEATURES,
338 (SAL_ERR_FEAT_MCA_SLV_TO_OS_INIT_SLV | SAL_ERR_FEAT_LOG_SBES),
339 0, 0, 0, 0, 0, 0);
340
341 return ret_stuff.status;
342}
343
344/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 * 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;
Russ Anderson8eac3752005-05-16 15:19:00 -0700475 SAL_CALL_REENTRANT(isrv, SN_SAL_POD_MODE, 0, 0, 0, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 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;
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700560 ia64_sal_oemcall_reentrant(&ret_stuff, SN_SAL_PARTITION_SERIAL_GET, 0,
561 0, 0, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (ret_stuff.status != 0)
563 return 0;
564 return ret_stuff.v0;
565}
566
567static inline u64
568sn_partition_serial_number_val(void) {
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700569 if (unlikely(sn_partition_serial_number == 0)) {
570 sn_partition_serial_number = ia64_sn_partition_serial_get();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 }
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700572 return sn_partition_serial_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573}
574
575/*
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700576 * Returns the physical address of the partition's reserved page through
577 * an iterative number of calls.
578 *
579 * On first call, 'cookie' and 'len' should be set to 0, and 'addr'
580 * set to the nasid of the partition whose reserved page's address is
581 * being sought.
582 * On subsequent calls, pass the values, that were passed back on the
583 * previous call.
584 *
585 * While the return status equals SALRET_MORE_PASSES, keep calling
586 * this function after first copying 'len' bytes starting at 'addr'
587 * into 'buf'. Once the return status equals SALRET_OK, 'addr' will
588 * be the physical address of the partition's reserved page. If the
589 * return status equals neither of these, an error as occurred.
590 */
591static inline s64
592sn_partition_reserved_page_pa(u64 buf, u64 *cookie, u64 *addr, u64 *len)
593{
594 struct ia64_sal_retval rv;
595 ia64_sal_oemcall_reentrant(&rv, SN_SAL_GET_PARTITION_ADDR, *cookie,
596 *addr, buf, *len, 0, 0, 0);
597 *cookie = rv.v0;
598 *addr = rv.v1;
599 *len = rv.v2;
600 return rv.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601}
602
603/*
604 * Register or unregister a physical address range being referenced across
605 * a partition boundary for which certain SAL errors should be scanned for,
606 * cleaned up and ignored. This is of value for kernel partitioning code only.
607 * Values for the operation argument:
608 * 1 = register this address range with SAL
609 * 0 = unregister this address range with SAL
610 *
611 * SAL maintains a reference count on an address range in case it is registered
612 * multiple times.
613 *
614 * On success, returns the reference count of the address range after the SAL
615 * call has performed the current registration/unregistration. Returns a
616 * negative value if an error occurred.
617 */
618static inline int
619sn_register_xp_addr_region(u64 paddr, u64 len, int operation)
620{
621 struct ia64_sal_retval ret_stuff;
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700622 ia64_sal_oemcall(&ret_stuff, SN_SAL_XP_ADDR_REGION, paddr, len,
623 (u64)operation, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 return ret_stuff.status;
625}
626
627/*
628 * Register or unregister an instruction range for which SAL errors should
629 * be ignored. If an error occurs while in the registered range, SAL jumps
630 * to return_addr after ignoring the error. Values for the operation argument:
631 * 1 = register this instruction range with SAL
632 * 0 = unregister this instruction range with SAL
633 *
634 * Returns 0 on success, or a negative value if an error occurred.
635 */
636static inline int
637sn_register_nofault_code(u64 start_addr, u64 end_addr, u64 return_addr,
638 int virtual, int operation)
639{
640 struct ia64_sal_retval ret_stuff;
641 u64 call;
642 if (virtual) {
643 call = SN_SAL_NO_FAULT_ZONE_VIRTUAL;
644 } else {
645 call = SN_SAL_NO_FAULT_ZONE_PHYSICAL;
646 }
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700647 ia64_sal_oemcall(&ret_stuff, call, start_addr, end_addr, return_addr,
648 (u64)1, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 return ret_stuff.status;
650}
651
652/*
653 * Change or query the coherence domain for this partition. Each cpu-based
654 * nasid is represented by a bit in an array of 64-bit words:
655 * 0 = not in this partition's coherency domain
656 * 1 = in this partition's coherency domain
657 *
658 * It is not possible for the local system's nasids to be removed from
659 * the coherency domain. Purpose of the domain arguments:
660 * new_domain = set the coherence domain to the given nasids
661 * old_domain = return the current coherence domain
662 *
663 * Returns 0 on success, or a negative value if an error occurred.
664 */
665static inline int
666sn_change_coherence(u64 *new_domain, u64 *old_domain)
667{
668 struct ia64_sal_retval ret_stuff;
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700669 ia64_sal_oemcall(&ret_stuff, SN_SAL_COHERENCE, (u64)new_domain,
670 (u64)old_domain, 0, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 return ret_stuff.status;
672}
673
674/*
675 * Change memory access protections for a physical address range.
676 * nasid_array is not used on Altix, but may be in future architectures.
677 * Available memory protection access classes are defined after the function.
678 */
679static inline int
680sn_change_memprotect(u64 paddr, u64 len, u64 perms, u64 *nasid_array)
681{
682 struct ia64_sal_retval ret_stuff;
683 int cnodeid;
684 unsigned long irq_flags;
685
686 cnodeid = nasid_to_cnodeid(get_node_number(paddr));
687 // spin_lock(&NODEPDA(cnodeid)->bist_lock);
688 local_irq_save(irq_flags);
Dean Nelsonb48fc7b2005-03-23 19:05:00 -0700689 ia64_sal_oemcall_nolock(&ret_stuff, SN_SAL_MEMPROTECT, paddr, len,
690 (u64)nasid_array, perms, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 local_irq_restore(irq_flags);
692 // spin_unlock(&NODEPDA(cnodeid)->bist_lock);
693 return ret_stuff.status;
694}
695#define SN_MEMPROT_ACCESS_CLASS_0 0x14a080
696#define SN_MEMPROT_ACCESS_CLASS_1 0x2520c2
697#define SN_MEMPROT_ACCESS_CLASS_2 0x14a1ca
698#define SN_MEMPROT_ACCESS_CLASS_3 0x14a290
699#define SN_MEMPROT_ACCESS_CLASS_6 0x084080
700#define SN_MEMPROT_ACCESS_CLASS_7 0x021080
701
702/*
703 * Turns off system power.
704 */
705static inline void
706ia64_sn_power_down(void)
707{
708 struct ia64_sal_retval ret_stuff;
709 SAL_CALL(ret_stuff, SN_SAL_SYSTEM_POWER_DOWN, 0, 0, 0, 0, 0, 0, 0);
Jack Steiner68b97532005-08-11 10:28:00 -0700710 while(1)
711 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 /* 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
Greg Howard67639de2005-04-25 13:28:52 -0700853/*
854 * Set up a node as the point of contact for system controller
855 * environmental event delivery.
856 */
857static inline int
858ia64_sn_sysctl_event_init(nasid_t nasid)
859{
860 struct ia64_sal_retval rv;
861 SAL_CALL_REENTRANT(rv, SN_SAL_SYSCTL_EVENT, (u64) nasid,
862 0, 0, 0, 0, 0, 0);
863 return (int) rv.v0;
864}
865
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866/**
867 * ia64_sn_get_fit_compt - read a FIT entry from the PROM header
868 * @nasid: NASID of node to read
869 * @index: FIT entry index to be retrieved (0..n)
870 * @fitentry: 16 byte buffer where FIT entry will be stored.
871 * @banbuf: optional buffer for retrieving banner
872 * @banlen: length of banner buffer
873 *
874 * Access to the physical PROM chips needs to be serialized since reads and
875 * writes can't occur at the same time, so we need to call into the SAL when
876 * we want to look at the FIT entries on the chips.
877 *
878 * Returns:
879 * %SALRET_OK if ok
880 * %SALRET_INVALID_ARG if index too big
881 * %SALRET_NOT_IMPLEMENTED if running on older PROM
882 * ??? if nasid invalid OR banner buffer not large enough
883 */
884static inline int
885ia64_sn_get_fit_compt(u64 nasid, u64 index, void *fitentry, void *banbuf,
886 u64 banlen)
887{
888 struct ia64_sal_retval rv;
889 SAL_CALL_NOLOCK(rv, SN_SAL_GET_FIT_COMPT, nasid, index, fitentry,
890 banbuf, banlen, 0, 0);
891 return (int) rv.status;
892}
893
894/*
895 * Initialize the SAL components of the system controller
896 * communication driver; specifically pass in a sizable buffer that
897 * can be used for allocation of subchannel queues as new subchannels
898 * are opened. "buf" points to the buffer, and "len" specifies its
899 * length.
900 */
901static inline int
902ia64_sn_irtr_init(nasid_t nasid, void *buf, int len)
903{
904 struct ia64_sal_retval rv;
905 SAL_CALL_REENTRANT(rv, SN_SAL_IROUTER_OP, SAL_IROUTER_INIT,
906 (u64) nasid, (u64) buf, (u64) len, 0, 0, 0);
907 return (int) rv.status;
908}
909
910/*
911 * Returns the nasid, subnode & slice corresponding to a SAPIC ID
912 *
913 * In:
914 * arg0 - SN_SAL_GET_SAPIC_INFO
915 * arg1 - sapicid (lid >> 16)
916 * Out:
917 * v0 - nasid
918 * v1 - subnode
919 * v2 - slice
920 */
921static inline u64
922ia64_sn_get_sapic_info(int sapicid, int *nasid, int *subnode, int *slice)
923{
924 struct ia64_sal_retval ret_stuff;
925
926 ret_stuff.status = 0;
927 ret_stuff.v0 = 0;
928 ret_stuff.v1 = 0;
929 ret_stuff.v2 = 0;
930 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SAPIC_INFO, sapicid, 0, 0, 0, 0, 0, 0);
931
932/***** BEGIN HACK - temp til old proms no longer supported ********/
933 if (ret_stuff.status == SALRET_NOT_IMPLEMENTED) {
934 if (nasid) *nasid = sapicid & 0xfff;
935 if (subnode) *subnode = (sapicid >> 13) & 1;
936 if (slice) *slice = (sapicid >> 12) & 3;
937 return 0;
938 }
939/***** END HACK *******/
940
941 if (ret_stuff.status < 0)
942 return ret_stuff.status;
943
944 if (nasid) *nasid = (int) ret_stuff.v0;
945 if (subnode) *subnode = (int) ret_stuff.v1;
946 if (slice) *slice = (int) ret_stuff.v2;
947 return 0;
948}
949
950/*
951 * Returns information about the HUB/SHUB.
952 * In:
953 * arg0 - SN_SAL_GET_SN_INFO
954 * arg1 - 0 (other values reserved for future use)
955 * Out:
956 * v0
957 * [7:0] - shub type (0=shub1, 1=shub2)
958 * [15:8] - Log2 max number of nodes in entire system (includes
959 * C-bricks, I-bricks, etc)
960 * [23:16] - Log2 of nodes per sharing domain
961 * [31:24] - partition ID
962 * [39:32] - coherency_id
963 * [47:40] - regionsize
964 * v1
965 * [15:0] - nasid mask (ex., 0x7ff for 11 bit nasid)
966 * [23:15] - bit position of low nasid bit
967 */
968static inline u64
969ia64_sn_get_sn_info(int fc, u8 *shubtype, u16 *nasid_bitmask, u8 *nasid_shift,
970 u8 *systemsize, u8 *sharing_domain_size, u8 *partid, u8 *coher, u8 *reg)
971{
972 struct ia64_sal_retval ret_stuff;
973
974 ret_stuff.status = 0;
975 ret_stuff.v0 = 0;
976 ret_stuff.v1 = 0;
977 ret_stuff.v2 = 0;
978 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_GET_SN_INFO, fc, 0, 0, 0, 0, 0, 0);
979
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 if (ret_stuff.status < 0)
981 return ret_stuff.status;
982
983 if (shubtype) *shubtype = ret_stuff.v0 & 0xff;
984 if (systemsize) *systemsize = (ret_stuff.v0 >> 8) & 0xff;
985 if (sharing_domain_size) *sharing_domain_size = (ret_stuff.v0 >> 16) & 0xff;
986 if (partid) *partid = (ret_stuff.v0 >> 24) & 0xff;
987 if (coher) *coher = (ret_stuff.v0 >> 32) & 0xff;
988 if (reg) *reg = (ret_stuff.v0 >> 40) & 0xff;
989 if (nasid_bitmask) *nasid_bitmask = (ret_stuff.v1 & 0xffff);
990 if (nasid_shift) *nasid_shift = (ret_stuff.v1 >> 16) & 0xff;
991 return 0;
992}
993
994/*
995 * This is the access point to the Altix PROM hardware performance
996 * and status monitoring interface. For info on using this, see
997 * include/asm-ia64/sn/sn2/sn_hwperf.h
998 */
999static inline int
1000ia64_sn_hwperf_op(nasid_t nasid, u64 opcode, u64 a0, u64 a1, u64 a2,
1001 u64 a3, u64 a4, int *v0)
1002{
1003 struct ia64_sal_retval rv;
1004 SAL_CALL_NOLOCK(rv, SN_SAL_HWPERF_OP, (u64)nasid,
1005 opcode, a0, a1, a2, a3, a4);
1006 if (v0)
1007 *v0 = (int) rv.v0;
1008 return (int) rv.status;
1009}
1010
Mark Goodwin4a5c13c2005-04-25 13:04:22 -07001011static inline int
Mark Goodwinecc3c302005-08-16 00:50:00 -07001012ia64_sn_ioif_get_pci_topology(u64 buf, u64 len)
Mark Goodwin4a5c13c2005-04-25 13:04:22 -07001013{
1014 struct ia64_sal_retval rv;
Mark Goodwinecc3c302005-08-16 00:50:00 -07001015 SAL_CALL_NOLOCK(rv, SN_SAL_IOIF_GET_PCI_TOPOLOGY, buf, len, 0, 0, 0, 0, 0);
Mark Goodwin4a5c13c2005-04-25 13:04:22 -07001016 return (int) rv.status;
1017}
1018
Russ Anderson93a07d02005-04-25 13:19:52 -07001019/*
1020 * BTE error recovery is implemented in SAL
1021 */
1022static inline int
1023ia64_sn_bte_recovery(nasid_t nasid)
1024{
1025 struct ia64_sal_retval rv;
1026
1027 rv.status = 0;
1028 SAL_CALL_NOLOCK(rv, SN_SAL_BTE_RECOVER, 0, 0, 0, 0, 0, 0, 0);
1029 if (rv.status == SALRET_NOT_IMPLEMENTED)
1030 return 0;
1031 return (int) rv.status;
1032}
1033
Jack Steiner71a5d022005-05-10 08:01:00 -07001034static inline int
1035ia64_sn_is_fake_prom(void)
1036{
1037 struct ia64_sal_retval rv;
1038 SAL_CALL_NOLOCK(rv, SN_SAL_FAKE_PROM, 0, 0, 0, 0, 0, 0, 0);
1039 return (rv.status == 0);
1040}
1041
Jack Steinera1cddb82005-08-31 08:05:00 -07001042static inline int
1043ia64_sn_get_prom_feature_set(int set, unsigned long *feature_set)
1044{
1045 struct ia64_sal_retval rv;
1046
1047 SAL_CALL_NOLOCK(rv, SN_SAL_GET_PROM_FEATURE_SET, set, 0, 0, 0, 0, 0, 0);
1048 if (rv.status != 0)
1049 return rv.status;
1050 *feature_set = rv.v0;
1051 return 0;
1052}
1053
1054static inline int
1055ia64_sn_set_os_feature(int feature)
1056{
1057 struct ia64_sal_retval rv;
1058
1059 SAL_CALL_NOLOCK(rv, SN_SAL_SET_OS_FEATURE_SET, feature, 0, 0, 0, 0, 0, 0);
1060 return rv.status;
1061}
1062
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063#endif /* _ASM_IA64_SN_SN_SAL_H */