patch-2_6_7-vs1_9_1_12
[linux-2.6.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/spinlock.h>
14 #include <linux/string.h>
15
16 #include <asm/page.h>
17 #include <asm/sal.h>
18 #include <asm/pal.h>
19
20 spinlock_t sal_lock __cacheline_aligned = SPIN_LOCK_UNLOCKED;
21 unsigned long sal_platform_features;
22
23 unsigned short sal_revision;
24 unsigned short sal_version;
25
26 #define SAL_MAJOR(x) ((x) >> 8)
27 #define SAL_MINOR(x) ((x) & 0xff)
28
29 static struct {
30         void *addr;     /* function entry point */
31         void *gpval;    /* gp value to use */
32 } pdesc;
33
34 static long
35 default_handler (void)
36 {
37         return -1;
38 }
39
40 ia64_sal_handler ia64_sal = (ia64_sal_handler) default_handler;
41 ia64_sal_desc_ptc_t *ia64_ptc_domain_info;
42
43 const char *
44 ia64_sal_strerror (long status)
45 {
46         const char *str;
47         switch (status) {
48               case 0: str = "Call completed without error"; break;
49               case 1: str = "Effect a warm boot of the system to complete "
50                               "the update"; break;
51               case -1: str = "Not implemented"; break;
52               case -2: str = "Invalid argument"; break;
53               case -3: str = "Call completed with error"; break;
54               case -4: str = "Virtual address not registered"; break;
55               case -5: str = "No information available"; break;
56               case -6: str = "Insufficient space to add the entry"; break;
57               case -7: str = "Invalid entry_addr value"; break;
58               case -8: str = "Invalid interrupt vector"; break;
59               case -9: str = "Requested memory not available"; break;
60               case -10: str = "Unable to write to the NVM device"; break;
61               case -11: str = "Invalid partition type specified"; break;
62               case -12: str = "Invalid NVM_Object id specified"; break;
63               case -13: str = "NVM_Object already has the maximum number "
64                                 "of partitions"; break;
65               case -14: str = "Insufficient space in partition for the "
66                                 "requested write sub-function"; break;
67               case -15: str = "Insufficient data buffer space for the "
68                                 "requested read record sub-function"; break;
69               case -16: str = "Scratch buffer required for the write/delete "
70                                 "sub-function"; break;
71               case -17: str = "Insufficient space in the NVM_Object for the "
72                                 "requested create sub-function"; break;
73               case -18: str = "Invalid value specified in the partition_rec "
74                                 "argument"; break;
75               case -19: str = "Record oriented I/O not supported for this "
76                                 "partition"; break;
77               case -20: str = "Bad format of record to be written or "
78                                 "required keyword variable not "
79                                 "specified"; break;
80               default: str = "Unknown SAL status code"; break;
81         }
82         return str;
83 }
84
85 void __init
86 ia64_sal_handler_init (void *entry_point, void *gpval)
87 {
88         /* fill in the SAL procedure descriptor and point ia64_sal to it: */
89         pdesc.addr = entry_point;
90         pdesc.gpval = gpval;
91         ia64_sal = (ia64_sal_handler) &pdesc;
92 }
93
94 static void __init
95 check_versions (struct ia64_sal_systab *systab)
96 {
97         sal_revision = (systab->sal_rev_major << 8) | systab->sal_rev_minor;
98         sal_version = (systab->sal_b_rev_major << 8) | systab->sal_b_rev_minor;
99
100         /* Check for broken firmware */
101         if ((sal_revision == SAL_VERSION_CODE(49, 29))
102             && (sal_version == SAL_VERSION_CODE(49, 29)))
103         {
104                 /*
105                  * Old firmware for zx2000 prototypes have this weird version number,
106                  * reset it to something sane.
107                  */
108                 sal_revision = SAL_VERSION_CODE(2, 8);
109                 sal_version = SAL_VERSION_CODE(0, 0);
110         }
111 }
112
113 static void __init
114 sal_desc_entry_point (void *p)
115 {
116         struct ia64_sal_desc_entry_point *ep = p;
117         ia64_pal_handler_init(__va(ep->pal_proc));
118         ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
119 }
120
121 #ifdef CONFIG_SMP
122 static void __init
123 set_smp_redirect (int flag)
124 {
125 #ifndef CONFIG_HOTPLUG_CPU
126         if (no_int_routing)
127                 smp_int_redirect &= ~flag;
128         else
129                 smp_int_redirect |= flag;
130 #else
131         /*
132          * For CPU Hotplug we dont want to do any chipset supported
133          * interrupt redirection. The reason is this would require that
134          * All interrupts be stopped and hard bind the irq to a cpu.
135          * Later when the interrupt is fired we need to set the redir hint
136          * on again in the vector. This is combersome for something that the
137          * user mode irq balancer will solve anyways.
138          */
139         no_int_routing=1;
140         smp_int_redirect &= ~flag;
141 #endif
142 }
143 #else
144 #define set_smp_redirect(flag)  do { } while (0)
145 #endif
146
147 static void __init
148 sal_desc_platform_feature (void *p)
149 {
150         struct ia64_sal_desc_platform_feature *pf = p;
151         sal_platform_features = pf->feature_mask;
152
153         printk(KERN_INFO "SAL Platform features:");
154         if (!sal_platform_features) {
155                 printk(" None\n");
156                 return;
157         }
158
159         if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
160                 printk(" BusLock");
161         if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
162                 printk(" IRQ_Redirection");
163                 set_smp_redirect(SMP_IRQ_REDIRECTION);
164         }
165         if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
166                 printk(" IPI_Redirection");
167                 set_smp_redirect(SMP_IPI_REDIRECTION);
168         }
169         if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
170                 printk(" ITC_Drift");
171         printk("\n");
172 }
173
174 #ifdef CONFIG_SMP
175 static void __init
176 sal_desc_ap_wakeup (void *p)
177 {
178         struct ia64_sal_desc_ap_wakeup *ap = p;
179
180         switch (ap->mechanism) {
181         case IA64_SAL_AP_EXTERNAL_INT:
182                 ap_wakeup_vector = ap->vector;
183                 printk(KERN_INFO "SAL: AP wakeup using external interrupt "
184                                 "vector 0x%lx\n", ap_wakeup_vector);
185                 break;
186         default:
187                 printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
188                 break;
189         }
190 }
191 #else
192 static void __init sal_desc_ap_wakeup(void *p) { }
193 #endif
194
195 void __init
196 ia64_sal_init (struct ia64_sal_systab *systab)
197 {
198         char *p;
199         int i;
200
201         if (!systab) {
202                 printk(KERN_WARNING "Hmm, no SAL System Table.\n");
203                 return;
204         }
205
206         if (strncmp(systab->signature, "SST_", 4) != 0)
207                 printk(KERN_ERR "bad signature in system table!");
208
209         check_versions(systab);
210
211         /* revisions are coded in BCD, so %x does the job for us */
212         printk(KERN_INFO "SAL %x.%x: %.32s %.32s%sversion %x.%x\n",
213                         SAL_MAJOR(sal_revision), SAL_MINOR(sal_revision),
214                         systab->oem_id, systab->product_id,
215                         systab->product_id[0] ? " " : "",
216                         SAL_MAJOR(sal_version), SAL_MINOR(sal_version));
217
218         p = (char *) (systab + 1);
219         for (i = 0; i < systab->entry_count; i++) {
220                 /*
221                  * The first byte of each entry type contains the type
222                  * descriptor.
223                  */
224                 switch (*p) {
225                 case SAL_DESC_ENTRY_POINT:
226                         sal_desc_entry_point(p);
227                         break;
228                 case SAL_DESC_PLATFORM_FEATURE:
229                         sal_desc_platform_feature(p);
230                         break;
231                 case SAL_DESC_PTC:
232                         ia64_ptc_domain_info = (ia64_sal_desc_ptc_t *)p;
233                         break;
234                 case SAL_DESC_AP_WAKEUP:
235                         sal_desc_ap_wakeup(p);
236                         break;
237                 }
238                 p += SAL_DESC_SIZE(*p);
239         }
240 }