ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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         if (no_int_routing)
126                 smp_int_redirect &= ~flag;
127         else
128                 smp_int_redirect |= flag;
129 }
130 #else
131 #define set_smp_redirect(flag)  do { } while (0)
132 #endif
133
134 static void __init
135 sal_desc_platform_feature (void *p)
136 {
137         struct ia64_sal_desc_platform_feature *pf = p;
138         sal_platform_features = pf->feature_mask;
139
140         printk(KERN_INFO "SAL Platform features:");
141         if (!sal_platform_features) {
142                 printk(" None\n");
143                 return;
144         }
145
146         if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
147                 printk(" BusLock");
148         if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
149                 printk(" IRQ_Redirection");
150                 set_smp_redirect(SMP_IRQ_REDIRECTION);
151         }
152         if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
153                 printk(" IPI_Redirection");
154                 set_smp_redirect(SMP_IPI_REDIRECTION);
155         }
156         if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
157                 printk(" ITC_Drift");
158         printk("\n");
159 }
160
161 #ifdef CONFIG_SMP
162 static void __init
163 sal_desc_ap_wakeup (void *p)
164 {
165         struct ia64_sal_desc_ap_wakeup *ap = p;
166
167         switch (ap->mechanism) {
168         case IA64_SAL_AP_EXTERNAL_INT:
169                 ap_wakeup_vector = ap->vector;
170                 printk(KERN_INFO "SAL: AP wakeup using external interrupt "
171                                 "vector 0x%lx\n", ap_wakeup_vector);
172                 break;
173         default:
174                 printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
175                 break;
176         }
177 }
178 #else
179 static void __init sal_desc_ap_wakeup(void *p) { }
180 #endif
181
182 void __init
183 ia64_sal_init (struct ia64_sal_systab *systab)
184 {
185         char *p;
186         int i;
187
188         if (!systab) {
189                 printk(KERN_WARNING "Hmm, no SAL System Table.\n");
190                 return;
191         }
192
193         if (strncmp(systab->signature, "SST_", 4) != 0)
194                 printk(KERN_ERR "bad signature in system table!");
195
196         check_versions(systab);
197
198         /* revisions are coded in BCD, so %x does the job for us */
199         printk(KERN_INFO "SAL %x.%x: %.32s %.32s%sversion %x.%x\n",
200                         SAL_MAJOR(sal_revision), SAL_MINOR(sal_revision),
201                         systab->oem_id, systab->product_id,
202                         systab->product_id[0] ? " " : "",
203                         SAL_MAJOR(sal_version), SAL_MINOR(sal_version));
204
205         p = (char *) (systab + 1);
206         for (i = 0; i < systab->entry_count; i++) {
207                 /*
208                  * The first byte of each entry type contains the type
209                  * descriptor.
210                  */
211                 switch (*p) {
212                 case SAL_DESC_ENTRY_POINT:
213                         sal_desc_entry_point(p);
214                         break;
215                 case SAL_DESC_PLATFORM_FEATURE:
216                         sal_desc_platform_feature(p);
217                         break;
218                 case SAL_DESC_PTC:
219                         ia64_ptc_domain_info = (ia64_sal_desc_ptc_t *)p;
220                         break;
221                 case SAL_DESC_AP_WAKEUP:
222                         sal_desc_ap_wakeup(p);
223                         break;
224                 }
225                 p += SAL_DESC_SIZE(*p);
226         }
227 }