import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / ia64 / kernel / sal.c
1 /*
2  * System Abstraction Layer (SAL) interface routines.
3  *
4  * Copyright (C) 1998, 1999, 2001, 2003 Hewlett-Packard Co
5  *      David Mosberger-Tang <davidm@hpl.hp.com>
6  * Copyright (C) 1999 VA Linux Systems
7  * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
8  */
9 #include <linux/config.h>
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/smp.h>
14 #include <linux/spinlock.h>
15 #include <linux/string.h>
16
17 #include <asm/page.h>
18 #include <asm/sal.h>
19 #include <asm/pal.h>
20
21 spinlock_t sal_lock __cacheline_aligned = SPIN_LOCK_UNLOCKED;
22 unsigned long sal_platform_features;
23
24 static struct {
25         void *addr;     /* function entry point */
26         void *gpval;    /* gp value to use */
27 } pdesc;
28
29 static long
30 default_handler (void)
31 {
32         return -1;
33 }
34
35 ia64_sal_handler ia64_sal = (ia64_sal_handler) default_handler;
36 ia64_sal_desc_ptc_t *ia64_ptc_domain_info;
37
38 const char *
39 ia64_sal_strerror (long status)
40 {
41         const char *str;
42         switch (status) {
43               case 0: str = "Call completed without error"; break;
44               case 1: str = "Effect a warm boot of the system to complete "
45                               "the update"; break;
46               case -1: str = "Not implemented"; break;
47               case -2: str = "Invalid argument"; break;
48               case -3: str = "Call completed with error"; break;
49               case -4: str = "Virtual address not registered"; break;
50               case -5: str = "No information available"; break;
51               case -6: str = "Insufficient space to add the entry"; break;
52               case -7: str = "Invalid entry_addr value"; break;
53               case -8: str = "Invalid interrupt vector"; break;
54               case -9: str = "Requested memory not available"; break;
55               case -10: str = "Unable to write to the NVM device"; break;
56               case -11: str = "Invalid partition type specified"; break;
57               case -12: str = "Invalid NVM_Object id specified"; break;
58               case -13: str = "NVM_Object already has the maximum number "
59                                 "of partitions"; break;
60               case -14: str = "Insufficient space in partition for the "
61                                 "requested write sub-function"; break;
62               case -15: str = "Insufficient data buffer space for the "
63                                 "requested read record sub-function"; break;
64               case -16: str = "Scratch buffer required for the write/delete "
65                                 "sub-function"; break;
66               case -17: str = "Insufficient space in the NVM_Object for the "
67                                 "requested create sub-function"; break;
68               case -18: str = "Invalid value specified in the partition_rec "
69                                 "argument"; break;
70               case -19: str = "Record oriented I/O not supported for this "
71                                 "partition"; break;
72               case -20: str = "Bad format of record to be written or "
73                                 "required keyword variable not "
74                                 "specified"; break;
75               default: str = "Unknown SAL status code"; break;
76         }
77         return str;
78 }
79
80 void __init
81 ia64_sal_handler_init (void *entry_point, void *gpval)
82 {
83         /* fill in the SAL procedure descriptor and point ia64_sal to it: */
84         pdesc.addr = entry_point;
85         pdesc.gpval = gpval;
86         ia64_sal = (ia64_sal_handler) &pdesc;
87 }
88
89
90 void __init
91 ia64_sal_init (struct ia64_sal_systab *systab)
92 {
93         unsigned long min, max;
94         char *p;
95         struct ia64_sal_desc_entry_point *ep;
96         int i;
97
98         if (!systab) {
99                 printk(KERN_WARNING "Hmm, no SAL System Table.\n");
100                 return;
101         }
102
103         if (strncmp(systab->signature, "SST_", 4) != 0)
104                 printk(KERN_ERR "bad signature in system table!");
105
106         /*
107          * revisions are coded in BCD, so %x does the job for us
108          */
109         printk(KERN_INFO "SAL v%x.%02x: oem=%.32s, product=%.32s\n",
110                systab->sal_rev_major, systab->sal_rev_minor,
111                systab->oem_id, systab->product_id);
112
113         min = ~0UL;
114         max = 0;
115
116         p = (char *) (systab + 1);
117         for (i = 0; i < systab->entry_count; i++) {
118                 /*
119                  * The first byte of each entry type contains the type desciptor.
120                  */
121                 switch (*p) {
122                       case SAL_DESC_ENTRY_POINT:
123                         ep = (struct ia64_sal_desc_entry_point *) p;
124                         printk(KERN_INFO "SAL: entry: pal_proc=0x%lx, sal_proc=0x%lx\n",
125                                ep->pal_proc, ep->sal_proc);
126                         ia64_pal_handler_init(__va(ep->pal_proc));
127                         ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
128                         break;
129
130                       case SAL_DESC_PTC:
131                         ia64_ptc_domain_info = (ia64_sal_desc_ptc_t *)p;
132                         break;
133
134                       case SAL_DESC_AP_WAKEUP:
135 #ifdef CONFIG_SMP
136                       {
137                               struct ia64_sal_desc_ap_wakeup *ap = (void *) p;
138
139                               switch (ap->mechanism) {
140                                     case IA64_SAL_AP_EXTERNAL_INT:
141                                       ap_wakeup_vector = ap->vector;
142                                       printk(KERN_INFO "SAL: AP wakeup using external interrupt "
143                                              "vector 0x%lx\n", ap_wakeup_vector);
144                                       break;
145
146                                     default:
147                                       printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
148                                       break;
149                               }
150                               break;
151                       }
152 #endif
153                       case SAL_DESC_PLATFORM_FEATURE:
154                       {
155                               struct ia64_sal_desc_platform_feature *pf = (void *) p;
156                               sal_platform_features = pf->feature_mask;
157                               printk(KERN_INFO "SAL: Platform features ");
158
159                               if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
160                                       printk("BusLock ");
161                               if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
162                                       printk("IRQ_Redirection ");
163 #ifdef CONFIG_SMP
164                                       if (no_int_routing)
165                                               smp_int_redirect &= ~SMP_IRQ_REDIRECTION;
166                                       else
167                                               smp_int_redirect |= SMP_IRQ_REDIRECTION;
168 #endif
169                               }
170                               if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
171                                       printk("IPI_Redirection ");
172 #ifdef CONFIG_SMP
173                                       if (no_int_routing)
174                                               smp_int_redirect &= ~SMP_IPI_REDIRECTION;
175                                       else
176                                               smp_int_redirect |= SMP_IPI_REDIRECTION;
177 #endif
178                               }
179                               if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
180                                       printk("ITC_Drift ");
181                               printk("\n");
182                               break;
183                       }
184
185                 }
186                 p += SAL_DESC_SIZE(*p);
187         }
188 }