📄 dmi_scan.c
字号:
#include <linux/config.h>#include <linux/types.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/init.h>#include <linux/apm_bios.h>#include <linux/slab.h>#include <asm/io.h>#include <linux/pm.h>#include <asm/keyboard.h>#include <asm/system.h>#include <linux/bootmem.h>#include "pci-i386.h"unsigned long dmi_broken;int is_sony_vaio_laptop;struct dmi_header{ u8 type; u8 length; u16 handle;};#define dmi_printk(x)//#define dmi_printk(x) printk xstatic char * __init dmi_string(struct dmi_header *dm, u8 s){ u8 *bp=(u8 *)dm; bp+=dm->length; if(!s) return ""; s--; while(s>0 && *bp) { bp+=strlen(bp); bp++; s--; } return bp;}/* * We have to be cautious here. We have seen BIOSes with DMI pointers * pointing to completely the wrong place for example */ static int __init dmi_table(u32 base, int len, int num, void (*decode)(struct dmi_header *)){ u8 *buf; struct dmi_header *dm; u8 *data; int i=0; buf = bt_ioremap(base, len); if(buf==NULL) return -1; data = buf; /* * Stop when we see all the items the table claimed to have * OR we run off the end of the table (also happens) */ while(i<num && data-buf+sizeof(struct dmi_header)<=len) { dm=(struct dmi_header *)data; /* * We want to know the total length (formated area and strings) * before decoding to make sure we won't run off the table in * dmi_decode or dmi_string */ data+=dm->length; while(data-buf<len-1 && (data[0] || data[1])) data++; if(data-buf<len-1) decode(dm); data+=2; i++; } bt_iounmap(buf, len); return 0;}inline static int __init dmi_checksum(u8 *buf){ u8 sum=0; int a; for(a=0; a<15; a++) sum+=buf[a]; return (sum==0);}static int __init dmi_iterate(void (*decode)(struct dmi_header *)){ u8 buf[15]; u32 fp=0xF0000;#ifdef CONFIG_SIMNOW /* * Skip on x86/64 with simnow. Will eventually go away * If you see this ifdef in 2.6pre mail me ! */ return -1;#endif while( fp < 0xFFFFF) { isa_memcpy_fromio(buf, fp, 15); if(memcmp(buf, "_DMI_", 5)==0 && dmi_checksum(buf)) { u16 num=buf[13]<<8|buf[12]; u16 len=buf[7]<<8|buf[6]; u32 base=buf[11]<<24|buf[10]<<16|buf[9]<<8|buf[8]; /* * DMI version 0.0 means that the real version is taken from * the SMBIOS version, which we don't know at this point. */ if(buf[14]!=0) dmi_printk((KERN_INFO "DMI %d.%d present.\n", buf[14]>>4, buf[14]&0x0F)); else dmi_printk((KERN_INFO "DMI present.\n")); dmi_printk((KERN_INFO "%d structures occupying %d bytes.\n", num, len)); dmi_printk((KERN_INFO "DMI table at 0x%08X.\n", base)); if(dmi_table(base,len, num, decode)==0) return 0; } fp+=16; } return -1;}enum{ DMI_BIOS_VENDOR, DMI_BIOS_VERSION, DMI_BIOS_DATE, DMI_SYS_VENDOR, DMI_PRODUCT_NAME, DMI_PRODUCT_VERSION, DMI_BOARD_VENDOR, DMI_BOARD_NAME, DMI_BOARD_VERSION, DMI_STRING_MAX};static char *dmi_ident[DMI_STRING_MAX];/* * Save a DMI string */ static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string){ char *d = (char*)dm; char *p = dmi_string(dm, d[string]); if(p==NULL || *p == 0) return; if (dmi_ident[slot]) return; dmi_ident[slot] = alloc_bootmem(strlen(p)+1); if(dmi_ident[slot]) strcpy(dmi_ident[slot], p); else printk(KERN_ERR "dmi_save_ident: out of memory.\n");}/* * DMI callbacks for problem boards */struct dmi_strmatch{ u8 slot; char *substr;};#define NONE 255struct dmi_blacklist{ int (*callback)(struct dmi_blacklist *); char *ident; struct dmi_strmatch matches[4];};#define NO_MATCH { NONE, NULL}#define MATCH(a,b) { a, b }/* * We have problems with IDE DMA on some platforms. In paticular the * KT7 series. On these it seems the newer BIOS has fixed them. The * rule needs to be improved to match specific BIOS revisions with * corruption problems static __init int disable_ide_dma(struct dmi_blacklist *d){#ifdef CONFIG_BLK_DEV_IDE extern int noautodma; if(noautodma == 0) { noautodma = 1; printk(KERN_INFO "%s series board detected. Disabling IDE DMA.\n", d->ident); }#endif return 0;} */ /* * Reboot options and system auto-detection code provided by * Dell Computer Corporation so their systems "just work". :-) *//* * Some machines require the "reboot=b" commandline option, this quirk makes that automatic. */static __init int set_bios_reboot(struct dmi_blacklist *d){ extern int reboot_thru_bios; if (reboot_thru_bios == 0) { reboot_thru_bios = 1; printk(KERN_INFO "%s series board detected. Selecting BIOS-method for reboots.\n", d->ident); } return 0;}/* * Some machines require the "reboot=s" commandline option, this quirk makes that automatic. */static __init int set_smp_reboot(struct dmi_blacklist *d){#ifdef CONFIG_SMP extern int reboot_smp; if (reboot_smp == 0) { reboot_smp = 1; printk(KERN_INFO "%s series board detected. Selecting SMP-method for reboots.\n", d->ident); }#endif return 0;}/* * Some machines require the "reboot=b,s" commandline option, this quirk makes that automatic. */static __init int set_smp_bios_reboot(struct dmi_blacklist *d){ set_smp_reboot(d); set_bios_reboot(d); return 0;}/* * Some bioses have a broken protected mode poweroff and need to use realmode */static __init int set_realmode_power_off(struct dmi_blacklist *d){ if (apm_info.realmode_power_off == 0) { apm_info.realmode_power_off = 1; printk(KERN_INFO "%s bios detected. Using realmode poweroff only.\n", d->ident); } return 0;}/* * Some laptops require interrupts to be enabled during APM calls */static __init int set_apm_ints(struct dmi_blacklist *d){ if (apm_info.allow_ints == 0) { apm_info.allow_ints = 1; printk(KERN_INFO "%s machine detected. Enabling interrupts during APM calls.\n", d->ident); } return 0;}/* * Some APM bioses corrupt memory or just plain do not work */static __init int apm_is_horked(struct dmi_blacklist *d){ if (apm_info.disabled == 0) { apm_info.disabled = 1; printk(KERN_INFO "%s machine detected. Disabling APM.\n", d->ident); } return 0;}static __init int apm_is_horked_d850md(struct dmi_blacklist *d){ if (apm_info.disabled == 0) { apm_info.disabled = 1; printk(KERN_ERR "%s machine detected. Disabling APM.\n", d->ident); printk(KERN_ERR "This bug is fixed in bios P15 which is available for \n"); printk(KERN_ERR "download from support.intel.com \n"); } return 0;}/* * Some APM bioses hang on APM idle calls */static __init int apm_likes_to_melt(struct dmi_blacklist *d){ if (apm_info.forbid_idle == 0) { apm_info.forbid_idle = 1; printk(KERN_INFO "%s machine detected. Disabling APM idle calls.\n", d->ident); } return 0;}/* * Some machines, usually laptops, can't handle an enabled local APIC. * The symptoms include hangs or reboots when suspending or resuming, * attaching or detaching the power cord, or entering BIOS setup screens * through magic key sequences. */static int __init local_apic_kills_bios(struct dmi_blacklist *d){#ifdef CONFIG_X86_LOCAL_APIC extern int dont_enable_local_apic; if (!dont_enable_local_apic) { dont_enable_local_apic = 1; printk(KERN_WARNING "%s with broken BIOS detected. " "Refusing to enable the local APIC.\n", d->ident); }#endif return 0;}/* * The Microstar 6163-2 (a.k.a Pro) mainboard will hang shortly after * resumes, and also at what appears to be asynchronous APM events, * if the local APIC is enabled. */static int __init apm_kills_local_apic(struct dmi_blacklist *d){#ifdef CONFIG_X86_LOCAL_APIC extern int dont_enable_local_apic; if (apm_info.bios.version && !dont_enable_local_apic) { dont_enable_local_apic = 1; printk(KERN_WARNING "%s with broken BIOS detected. " "Refusing to enable the local APIC.\n", d->ident); }#endif return 0;}/* * The Intel AL440LX mainboard will hang randomly if the local APIC * timer is running and the APM BIOS hasn't been disabled. */static int __init apm_kills_local_apic_timer(struct dmi_blacklist *d){#ifdef CONFIG_X86_LOCAL_APIC extern int dont_use_local_apic_timer; if (apm_info.bios.version && !dont_use_local_apic_timer) { dont_use_local_apic_timer = 1; printk(KERN_WARNING "%s with broken BIOS detected. " "The local APIC timer will not be used.\n", d->ident); }#endif return 0;}/* * Check for clue free BIOS implementations who use * the following QA technique * * [ Write BIOS Code ]<------ * | ^ * < Does it Compile >----N-- * |Y ^ * < Does it Boot Win98 >-N-- * |Y * [Ship It] * * Phoenix A04 08/24/2000 is known bad (Dell Inspiron 5000e) * Phoenix A07 09/29/2000 is known good (Dell Inspiron 5000) */static __init int broken_apm_power(struct dmi_blacklist *d){ apm_info.get_power_status_broken = 1; printk(KERN_WARNING "BIOS strings suggest APM bugs, disabling power status reporting.\n"); return 0;} /* * Check for a Sony Vaio system * * On a Sony system we want to enable the use of the sonypi * driver for Sony-specific goodies like the camera and jogdial. * We also want to avoid using certain functions of the PnP BIOS. */static __init int sony_vaio_laptop(struct dmi_blacklist *d){ if (is_sony_vaio_laptop == 0) { is_sony_vaio_laptop = 1; printk(KERN_INFO "%s laptop detected.\n", d->ident); } return 0;}/* * This bios swaps the APM minute reporting bytes over (Many sony laptops * have this problem). */ static __init int swab_apm_power_in_minutes(struct dmi_blacklist *d){ apm_info.get_power_status_swabinminutes = 1; printk(KERN_WARNING "BIOS strings suggest APM reports battery life in minutes and wrong byte order.\n"); return 0;}/* * The Intel 440GX hall of shame. * * On many (all we have checked) of these boxes the $PIRQ table is wrong. * The MP1.4 table is right however and so SMP kernels tend to work. */ extern int skip_ioapic_setup;extern int broken_440gx_bios;extern unsigned int pci_probe;static __init int broken_pirq(struct dmi_blacklist *d){ printk(KERN_ERR " *** Possibly defective BIOS detected (irqtable)\n"); printk(KERN_ERR " *** Many BIOSes matching this signature have incorrect IRQ routing tables.\n"); printk(KERN_ERR " *** If you see IRQ problems, in particular SCSI resets and hangs at boot\n"); printk(KERN_ERR " *** contact your hardware vendor and ask about updates.\n"); printk(KERN_INFO " *** Building an SMP kernel may evade the bug some of the time.\n");#ifdef CONFIG_X86_IO_APIC skip_ioapic_setup = 0;#endif broken_440gx_bios = 1; pci_probe |= PCI_BIOS_IRQ_SCAN; return 0;}/* * ASUS K7V-RM has broken ACPI table defining sleep modes */static __init int broken_acpi_Sx(struct dmi_blacklist *d){ printk(KERN_WARNING "Detected ASUS mainboard with broken ACPI sleep table\n"); dmi_broken |= BROKEN_ACPI_Sx; return 0;}/* * Toshiba keyboard likes to repeat keys when they are not repeated. */static __init int broken_toshiba_keyboard(struct dmi_blacklist *d){ printk(KERN_WARNING "Toshiba with broken keyboard detected. If your keyboard sometimes generates 3 keypresses instead of one, contact pavel@ucw.cz\n"); return 0;}/* * Toshiba fails to preserve interrupts over S1 */static __init int init_ints_after_s1(struct dmi_blacklist *d){ printk(KERN_WARNING "Toshiba with broken S1 detected.\n"); dmi_broken |= BROKEN_INIT_AFTER_S1; return 0;}/* * Some Bioses enable the PS/2 mouse (touchpad) at resume, even if it * was disabled before the suspend. Linux gets terribly confused by that.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -