xen-vtx-unstable

view xen/arch/x86/dmi_scan.c @ 6774:4d899a738d59

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