vserver 1.9.5.x5
[linux-2.6.git] / arch / i386 / kernel / dmi_scan.c
1 #include <linux/types.h>
2 #include <linux/kernel.h>
3 #include <linux/string.h>
4 #include <linux/init.h>
5 #include <linux/module.h>
6 #include <linux/slab.h>
7 #include <linux/acpi.h>
8 #include <asm/io.h>
9 #include <linux/pm.h>
10 #include <asm/system.h>
11 #include <linux/dmi.h>
12 #include <linux/bootmem.h>
13
14
15 int es7000_plat = 0;
16
17 struct dmi_header
18 {
19         u8      type;
20         u8      length;
21         u16     handle;
22 };
23
24 #undef DMI_DEBUG
25
26 #ifdef DMI_DEBUG
27 #define dmi_printk(x) printk x
28 #else
29 #define dmi_printk(x)
30 #endif
31
32 static char * __init dmi_string(struct dmi_header *dm, u8 s)
33 {
34         u8 *bp=(u8 *)dm;
35         bp+=dm->length;
36         if(!s)
37                 return "";
38         s--;
39         while(s>0 && *bp)
40         {
41                 bp+=strlen(bp);
42                 bp++;
43                 s--;
44         }
45         return bp;
46 }
47
48 /*
49  *      We have to be cautious here. We have seen BIOSes with DMI pointers
50  *      pointing to completely the wrong place for example
51  */
52  
53 static int __init dmi_table(u32 base, int len, int num, void (*decode)(struct dmi_header *))
54 {
55         u8 *buf;
56         struct dmi_header *dm;
57         u8 *data;
58         int i=0;
59                 
60         buf = bt_ioremap(base, len);
61         if(buf==NULL)
62                 return -1;
63
64         data = buf;
65
66         /*
67          *      Stop when we see all the items the table claimed to have
68          *      OR we run off the end of the table (also happens)
69          */
70  
71         while(i<num && data-buf+sizeof(struct dmi_header)<=len)
72         {
73                 dm=(struct dmi_header *)data;
74                 /*
75                  *  We want to know the total length (formated area and strings)
76                  *  before decoding to make sure we won't run off the table in
77                  *  dmi_decode or dmi_string
78                  */
79                 data+=dm->length;
80                 while(data-buf<len-1 && (data[0] || data[1]))
81                         data++;
82                 if(data-buf<len-1)
83                         decode(dm);
84                 data+=2;
85                 i++;
86         }
87         bt_iounmap(buf, len);
88         return 0;
89 }
90
91
92 inline static int __init dmi_checksum(u8 *buf)
93 {
94         u8 sum=0;
95         int a;
96         
97         for(a=0; a<15; a++)
98                 sum+=buf[a];
99         return (sum==0);
100 }
101
102 static int __init dmi_iterate(void (*decode)(struct dmi_header *))
103 {
104         u8 buf[15];
105         char __iomem *p, *q;
106
107         /*
108          * no iounmap() for that ioremap(); it would be a no-op, but it's
109          * so early in setup that sucker gets confused into doing what
110          * it shouldn't if we actually call it.
111          */
112         p = ioremap(0xF0000, 0x10000);
113         if (p == NULL)
114                 return -1;
115         for (q = p; q < p + 0x10000; q += 16) {
116                 memcpy_fromio(buf, q, 15);
117                 if(memcmp(buf, "_DMI_", 5)==0 && dmi_checksum(buf))
118                 {
119                         u16 num=buf[13]<<8|buf[12];
120                         u16 len=buf[7]<<8|buf[6];
121                         u32 base=buf[11]<<24|buf[10]<<16|buf[9]<<8|buf[8];
122
123                         /*
124                          * DMI version 0.0 means that the real version is taken from
125                          * the SMBIOS version, which we don't know at this point.
126                          */
127                         if(buf[14]!=0)
128                                 printk(KERN_INFO "DMI %d.%d present.\n",
129                                         buf[14]>>4, buf[14]&0x0F);
130                         else
131                                 printk(KERN_INFO "DMI present.\n");
132                         dmi_printk((KERN_INFO "%d structures occupying %d bytes.\n",
133                                 num, len));
134                         dmi_printk((KERN_INFO "DMI table at 0x%08X.\n",
135                                 base));
136                         if(dmi_table(base,len, num, decode)==0)
137                                 return 0;
138                 }
139         }
140         return -1;
141 }
142
143 static char *dmi_ident[DMI_STRING_MAX];
144
145 /*
146  *      Save a DMI string
147  */
148  
149 static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
150 {
151         char *d = (char*)dm;
152         char *p = dmi_string(dm, d[string]);
153         if(p==NULL || *p == 0)
154                 return;
155         if (dmi_ident[slot])
156                 return;
157         dmi_ident[slot] = alloc_bootmem(strlen(p)+1);
158         if(dmi_ident[slot])
159                 strcpy(dmi_ident[slot], p);
160         else
161                 printk(KERN_ERR "dmi_save_ident: out of memory.\n");
162 }
163
164 /*
165  * Ugly compatibility crap.
166  */
167 #define dmi_blacklist   dmi_system_id
168 #define NO_MATCH        { DMI_NONE, NULL}
169 #define MATCH           DMI_MATCH
170
171 /*
172  * Toshiba keyboard likes to repeat keys when they are not repeated.
173  */
174
175 static __init int broken_toshiba_keyboard(struct dmi_blacklist *d)
176 {
177         printk(KERN_WARNING "Toshiba with broken keyboard detected. If your keyboard sometimes generates 3 keypresses instead of one, see http://davyd.ucc.asn.au/projects/toshiba/README\n");
178         return 0;
179 }
180
181
182 #ifdef CONFIG_ACPI_SLEEP
183 static __init int reset_videomode_after_s3(struct dmi_blacklist *d)
184 {
185         /* See acpi_wakeup.S */
186         extern long acpi_video_flags;
187         acpi_video_flags |= 2;
188         return 0;
189 }
190 #endif
191
192
193 #ifdef  CONFIG_ACPI_BOOT
194 extern int acpi_force;
195
196 static __init __attribute__((unused)) int dmi_disable_acpi(struct dmi_blacklist *d) 
197
198         if (!acpi_force) { 
199                 printk(KERN_NOTICE "%s detected: acpi off\n",d->ident); 
200                 disable_acpi();
201         } else { 
202                 printk(KERN_NOTICE 
203                        "Warning: DMI blacklist says broken, but acpi forced\n"); 
204         }
205         return 0;
206
207
208 /*
209  * Limit ACPI to CPU enumeration for HT
210  */
211 static __init __attribute__((unused)) int force_acpi_ht(struct dmi_blacklist *d) 
212
213         if (!acpi_force) { 
214                 printk(KERN_NOTICE "%s detected: force use of acpi=ht\n", d->ident); 
215                 disable_acpi();
216                 acpi_ht = 1; 
217         } else { 
218                 printk(KERN_NOTICE 
219                        "Warning: acpi=force overrules DMI blacklist: acpi=ht\n"); 
220         }
221         return 0;
222
223 #endif
224
225 #ifdef  CONFIG_ACPI_PCI
226 static __init int disable_acpi_irq(struct dmi_blacklist *d) 
227 {
228         if (!acpi_force) {
229                 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
230                        d->ident);       
231                 acpi_noirq_set();
232         }
233         return 0;
234 }
235 static __init int disable_acpi_pci(struct dmi_blacklist *d) 
236 {
237         if (!acpi_force) {
238                 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
239                        d->ident);       
240                 acpi_disable_pci();
241         }
242         return 0;
243 }  
244 #endif
245
246 /*
247  *      Process the DMI blacklists
248  */
249  
250
251 /*
252  *      This will be expanded over time to force things like the APM 
253  *      interrupt mask settings according to the laptop
254  */
255  
256 static __initdata struct dmi_blacklist dmi_blacklist[]={
257
258         { broken_toshiba_keyboard, "Toshiba Satellite 4030cdt", { /* Keyboard generates spurious repeats */
259                         MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),
260                         NO_MATCH, NO_MATCH, NO_MATCH
261                         } },
262 #ifdef CONFIG_ACPI_SLEEP
263         { reset_videomode_after_s3, "Toshiba Satellite 4030cdt", { /* Reset video mode after returning from ACPI S3 sleep */
264                         MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),
265                         NO_MATCH, NO_MATCH, NO_MATCH
266                         } },
267 #endif
268
269 #ifdef  CONFIG_ACPI_BOOT
270         /*
271          * If your system is blacklisted here, but you find that acpi=force
272          * works for you, please contact acpi-devel@sourceforge.net
273          */
274
275         /*
276          *      Boxes that need ACPI disabled
277          */
278
279         { dmi_disable_acpi, "IBM Thinkpad", {
280                         MATCH(DMI_BOARD_VENDOR, "IBM"),
281                         MATCH(DMI_BOARD_NAME, "2629H1G"),
282                         NO_MATCH, NO_MATCH }},
283
284         /*
285          *      Boxes that need acpi=ht 
286          */
287
288         { force_acpi_ht, "FSC Primergy T850", {
289                         MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
290                         MATCH(DMI_PRODUCT_NAME, "PRIMERGY T850"),
291                         NO_MATCH, NO_MATCH }},
292
293         { force_acpi_ht, "DELL GX240", {
294                         MATCH(DMI_BOARD_VENDOR, "Dell Computer Corporation"),
295                         MATCH(DMI_BOARD_NAME, "OptiPlex GX240"),
296                         NO_MATCH, NO_MATCH }},
297
298         { force_acpi_ht, "HP VISUALIZE NT Workstation", {
299                         MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
300                         MATCH(DMI_PRODUCT_NAME, "HP VISUALIZE NT Workstation"),
301                         NO_MATCH, NO_MATCH }},
302
303         { force_acpi_ht, "Compaq Workstation W8000", {
304                         MATCH(DMI_SYS_VENDOR, "Compaq"),
305                         MATCH(DMI_PRODUCT_NAME, "Workstation W8000"),
306                         NO_MATCH, NO_MATCH }},
307
308         { force_acpi_ht, "ASUS P4B266", {
309                         MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
310                         MATCH(DMI_BOARD_NAME, "P4B266"),
311                         NO_MATCH, NO_MATCH }},
312
313         { force_acpi_ht, "ASUS P2B-DS", {
314                         MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
315                         MATCH(DMI_BOARD_NAME, "P2B-DS"),
316                         NO_MATCH, NO_MATCH }},
317
318         { force_acpi_ht, "ASUS CUR-DLS", {
319                         MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
320                         MATCH(DMI_BOARD_NAME, "CUR-DLS"),
321                         NO_MATCH, NO_MATCH }},
322
323         { force_acpi_ht, "ABIT i440BX-W83977", {
324                         MATCH(DMI_BOARD_VENDOR, "ABIT <http://www.abit.com>"),
325                         MATCH(DMI_BOARD_NAME, "i440BX-W83977 (BP6)"),
326                         NO_MATCH, NO_MATCH }},
327
328         { force_acpi_ht, "IBM Bladecenter", {
329                         MATCH(DMI_BOARD_VENDOR, "IBM"),
330                         MATCH(DMI_BOARD_NAME, "IBM eServer BladeCenter HS20"),
331                         NO_MATCH, NO_MATCH }},
332
333         { force_acpi_ht, "IBM eServer xSeries 360", {
334                         MATCH(DMI_BOARD_VENDOR, "IBM"),
335                         MATCH(DMI_BOARD_NAME, "eServer xSeries 360"),
336                         NO_MATCH, NO_MATCH }},
337
338         { force_acpi_ht, "IBM eserver xSeries 330", {
339                         MATCH(DMI_BOARD_VENDOR, "IBM"),
340                         MATCH(DMI_BOARD_NAME, "eserver xSeries 330"),
341                         NO_MATCH, NO_MATCH }},
342
343         { force_acpi_ht, "IBM eserver xSeries 440", {
344                         MATCH(DMI_BOARD_VENDOR, "IBM"),
345                         MATCH(DMI_PRODUCT_NAME, "eserver xSeries 440"),
346                         NO_MATCH, NO_MATCH }},
347
348 #endif  // CONFIG_ACPI_BOOT
349
350 #ifdef  CONFIG_ACPI_PCI
351         /*
352          *      Boxes that need ACPI PCI IRQ routing disabled
353          */
354
355         { disable_acpi_irq, "ASUS A7V", {
356                         MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
357                         MATCH(DMI_BOARD_NAME, "<A7V>"),
358                         /* newer BIOS, Revision 1011, does work */
359                         MATCH(DMI_BIOS_VERSION, "ASUS A7V ACPI BIOS Revision 1007"),
360                         NO_MATCH }},
361
362         /*
363          *      Boxes that need ACPI PCI IRQ routing and PCI scan disabled
364          */
365         { disable_acpi_pci, "ASUS PR-DLS", {    /* _BBN 0 bug */
366                         MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
367                         MATCH(DMI_BOARD_NAME, "PR-DLS"),
368                         MATCH(DMI_BIOS_VERSION, "ASUS PR-DLS ACPI BIOS Revision 1010"),
369                         MATCH(DMI_BIOS_DATE, "03/21/2003") }},
370
371         { disable_acpi_pci, "Acer TravelMate 36x Laptop", {
372                         MATCH(DMI_SYS_VENDOR, "Acer"),
373                         MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
374                         NO_MATCH, NO_MATCH
375                         } },
376
377 #endif
378
379         { NULL, }
380 };
381
382 /*
383  *      Process a DMI table entry. Right now all we care about are the BIOS
384  *      and machine entries. For 2.5 we should pull the smbus controller info
385  *      out of here.
386  */
387
388 static void __init dmi_decode(struct dmi_header *dm)
389 {
390 #ifdef DMI_DEBUG
391         u8 *data = (u8 *)dm;
392 #endif
393         
394         switch(dm->type)
395         {
396                 case  0:
397                         dmi_printk(("BIOS Vendor: %s\n",
398                                 dmi_string(dm, data[4])));
399                         dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
400                         dmi_printk(("BIOS Version: %s\n", 
401                                 dmi_string(dm, data[5])));
402                         dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
403                         dmi_printk(("BIOS Release: %s\n",
404                                 dmi_string(dm, data[8])));
405                         dmi_save_ident(dm, DMI_BIOS_DATE, 8);
406                         break;
407                 case 1:
408                         dmi_printk(("System Vendor: %s\n",
409                                 dmi_string(dm, data[4])));
410                         dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
411                         dmi_printk(("Product Name: %s\n",
412                                 dmi_string(dm, data[5])));
413                         dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
414                         dmi_printk(("Version: %s\n",
415                                 dmi_string(dm, data[6])));
416                         dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
417                         dmi_printk(("Serial Number: %s\n",
418                                 dmi_string(dm, data[7])));
419                         break;
420                 case 2:
421                         dmi_printk(("Board Vendor: %s\n",
422                                 dmi_string(dm, data[4])));
423                         dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
424                         dmi_printk(("Board Name: %s\n",
425                                 dmi_string(dm, data[5])));
426                         dmi_save_ident(dm, DMI_BOARD_NAME, 5);
427                         dmi_printk(("Board Version: %s\n",
428                                 dmi_string(dm, data[6])));
429                         dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
430                         break;
431         }
432 }
433
434 void __init dmi_scan_machine(void)
435 {
436         int err = dmi_iterate(dmi_decode);
437         if(err == 0)
438                 dmi_check_system(dmi_blacklist);
439         else
440                 printk(KERN_INFO "DMI not present.\n");
441 }
442
443
444 /**
445  *      dmi_check_system - check system DMI data
446  *      @list: array of dmi_system_id structures to match against
447  *
448  *      Walk the blacklist table running matching functions until someone
449  *      returns non zero or we hit the end. Callback function is called for
450  *      each successfull match. Returns the number of matches.
451  */
452 int dmi_check_system(struct dmi_system_id *list)
453 {
454         int i, count = 0;
455         struct dmi_system_id *d = list;
456
457         while (d->ident) {
458                 for (i = 0; i < ARRAY_SIZE(d->matches); i++) {
459                         int s = d->matches[i].slot;
460                         if (s == DMI_NONE)
461                                 continue;
462                         if (dmi_ident[s] && strstr(dmi_ident[s], d->matches[i].substr))
463                                 continue;
464                         /* No match */
465                         goto fail;
466                 }
467                 if (d->callback && d->callback(d))
468                         break;
469                 count++;
470 fail:           d++;
471         }
472
473         return count;
474 }
475
476 EXPORT_SYMBOL(dmi_check_system);
477
478 /**
479  *      dmi_get_system_info - return DMI data value
480  *      @field: data index (see enum dmi_filed)
481  *
482  *      Returns one DMI data value, can be used to perform
483  *      complex DMI data checks.
484  */
485 char * dmi_get_system_info(int field)
486 {
487         return dmi_ident[field];
488 }
489
490 EXPORT_SYMBOL(dmi_get_system_info);