ia64/xen-unstable

view xen/arch/x86/dmi_scan.c @ 19835:edfdeb150f27

Fix buildsystem to detect udev > version 124

udev removed the udevinfo symlink from versions higher than 123 and
xen's build-system could not detect if udev is in place and has the
required version.

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