⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i8k.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 2 页
字号:
    case I8K_BIOS_VERSION:	if (copy_to_user((int *)arg, &val, 4)) {	    return -EFAULT;	}	break;    case I8K_MACHINE_ID:	if (copy_to_user((int *)arg, buff, 16)) {	    return -EFAULT;	}	break;    default:	if (copy_to_user((int *)arg, &val, sizeof(int))) {	    return -EFAULT;	}	break;    }    return 0;}/* * Print the information for /proc/i8k. */static int i8k_get_info(char *buffer, char **start, off_t fpos, int length){    int n, fn_key, cpu_temp, ac_power;    int left_fan, right_fan, left_speed, right_speed;    cpu_temp     = i8k_get_cpu_temp();			/* 11100 祍 */    left_fan     = i8k_get_fan_status(I8K_FAN_LEFT);	/*   580 祍 */    right_fan    = i8k_get_fan_status(I8K_FAN_RIGHT);	/*   580 祍 */    left_speed   = i8k_get_fan_speed(I8K_FAN_LEFT);	/*   580 祍 */    right_speed  = i8k_get_fan_speed(I8K_FAN_RIGHT);	/*   580 祍 */    fn_key       = i8k_get_fn_status();			/*   750 祍 */    if (power_status) {	ac_power = i8k_get_power_status();		/* 14700 祍 */    } else {	ac_power = -1;    }    /*     * Info:     *     * 1)  Format version (this will change if format changes)     * 2)  BIOS version     * 3)  BIOS machine ID     * 4)  Cpu temperature     * 5)  Left fan status     * 6)  Right fan status     * 7)  Left fan speed     * 8)  Right fan speed     * 9)  AC power     * 10) Fn Key status     */    n = sprintf(buffer, "%s %s %s %d %d %d %d %d %d %d\n",		I8K_PROC_FMT,		bios_version,		serial_number,		cpu_temp,		left_fan,		right_fan,		left_speed,		right_speed,		ac_power,		fn_key);    return n;}static ssize_t i8k_read(struct file *f, char *buffer, size_t len, loff_t *fpos){    int n;    char info[128];    n = i8k_get_info(info, NULL, 0, 128);    if (n <= 0) {	return n;    }    if (*fpos >= n) {	return 0;    }    if ((*fpos + len) >= n) {	len = n - *fpos;    }    if (copy_to_user(buffer, info, len) != 0) {	return -EFAULT;    }    *fpos += len;    return len;}static char* __init string_trim(char *s, int size){    int len;    char *p;    if ((len = strlen(s)) > size) {	len = size;    }    for (p=s+len-1; len && (*p==' '); len--,p--) {	*p = '\0';    }    return s;}/* DMI code, stolen from arch/i386/kernel/dmi_scan.c *//* * |<-- dmi->length -->| * |                   | * |dmi header    s=N  | string1,\0, ..., stringN,\0, ..., \0 *                |                       | *                +-----------------------+ */static char* __init dmi_string(DMIHeader *dmi, u8 s){    u8 *p;    if (!s) {	return "";    }    s--;    p = (u8 *)dmi + dmi->length;    while (s > 0) {	p += strlen(p);	p++;	s--;    }    return p;}static void __init dmi_decode(DMIHeader *dmi){    u8 *data = (u8 *) dmi;    char *p;#ifdef I8K_DEBUG    int i;    printk("%08x ", (int)data);    for (i=0; i<data[1] && i<64; i++) {	printk("%02x ", data[i]);    }    printk("\n");#endif    switch (dmi->type) {    case  0:	/* BIOS Information */	p = dmi_string(dmi,data[5]);	if (*p) {	    strncpy(bios_version, p, sizeof(bios_version));	    string_trim(bios_version, sizeof(bios_version));	}	break;	    case 1:	/* System Information */	p = dmi_string(dmi,data[4]);	if (*p) {	    strncpy(system_vendor, p, sizeof(system_vendor));	    string_trim(system_vendor, sizeof(system_vendor));	}	p = dmi_string(dmi,data[5]);	if (*p) {	    strncpy(product_name, p, sizeof(product_name));	    string_trim(product_name, sizeof(product_name));	}	p = dmi_string(dmi,data[7]);	if (*p) {	    strncpy(serial_number, p, sizeof(serial_number));	    string_trim(serial_number, sizeof(serial_number));	}	break;    }}static int __init dmi_table(u32 base, int len, int num, void (*fn)(DMIHeader*)){    u8 *buf;    u8 *data;    DMIHeader *dmi;    int i = 1;    buf = ioremap(base, len);    if (buf == NULL) {	return -1;    }    data = buf;    /*     * Stop when we see al the items the table claimed to have     * or we run off the end of the table (also happens)     */    while ((i<num) && ((data-buf) < len)) {	dmi = (DMIHeader *)data;	/*	 * Avoid misparsing crud if the length of the last	 * record is crap	 */	if ((data-buf+dmi->length) >= len) {	    break;	}	fn(dmi);	data += dmi->length;	/*	 * Don't go off the end of the data if there is	 * stuff looking like string fill past the end	 */	while (((data-buf) < len) && (*data || data[1])) {	    data++;	}	data += 2;	i++;    }    iounmap(buf);    return 0;}static int __init dmi_iterate(void (*decode)(DMIHeader *)){    unsigned char buf[20];    long fp = 0x000e0000L;    fp -= 16;    while (fp < 0x000fffffL) {	fp += 16;	isa_memcpy_fromio(buf, fp, 20);	if (memcmp(buf, "_DMI_", 5)==0) {	    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];#ifdef I8K_DEBUG	    printk(KERN_INFO "DMI %d.%d present.\n",		   buf[14]>>4, buf[14]&0x0F);	    printk(KERN_INFO "%d structures occupying %d bytes.\n",		   buf[13]<<8 | buf[12],		   buf [7]<<8 | buf[6]);	    printk(KERN_INFO "DMI table at 0x%08X.\n",		   buf[11]<<24 | buf[10]<<16 | buf[9]<<8 | buf[8]);#endif	    if (dmi_table(base, len, num, decode)==0) {		return 0;	    }	}    }    return -1;}/* end of DMI code *//* * Get DMI information. */static int __init i8k_dmi_probe(void){    char **p;    if (dmi_iterate(dmi_decode) != 0) {	printk(KERN_INFO "i8k: unable to get DMI information\n");	return -ENODEV;    }    if (strncmp(system_vendor,DELL_SIGNATURE,strlen(DELL_SIGNATURE)) != 0) {	printk(KERN_INFO "i8k: not running on a Dell system\n");	return -ENODEV;    }    for (p=supported_models; ; p++) {	if (!*p) {	    printk(KERN_INFO "i8k: unsupported model: %s\n", product_name);	    return -ENODEV;	}	if (strncmp(product_name,*p,strlen(*p)) == 0) {	    break;	}    }    return 0;}/* * Probe for the presence of a supported laptop. */static int __init i8k_probe(void){    char buff[4];    int version;    int smm_found = 0;    /*     * Get DMI information     */    if (i8k_dmi_probe() != 0) {	printk(KERN_INFO "i8k: vendor=%s, model=%s, version=%s\n",	       system_vendor, product_name, bios_version);    }    /*     * Get SMM Dell signature     */    if (i8k_get_dell_signature() != 0) {	printk(KERN_INFO "i8k: unable to get SMM Dell signature\n");    } else {	smm_found = 1;    }    /*     * Get SMM BIOS version.     */    version = i8k_get_bios_version();    if (version <= 0) {	printk(KERN_INFO "i8k: unable to get SMM BIOS version\n");    } else {	smm_found = 1;	buff[0] = (version >> 16) & 0xff;	buff[1] = (version >>  8) & 0xff;	buff[2] = (version)       & 0xff;	buff[3] = '\0';	/*	 * If DMI BIOS version is unknown use SMM BIOS version.	 */	if (bios_version[0] == '?') {	    strcpy(bios_version, buff);	}	/*	 * Check if the two versions match.	 */	if (strncmp(buff,bios_version,sizeof(bios_version)) != 0) {	    printk(KERN_INFO "i8k: BIOS version mismatch: %s != %s\n",		   buff, bios_version);	}    }    if (!smm_found && !force) {	return -ENODEV;    }    return 0;}#ifdef MODULEstatic#endifint __init i8k_init(void){    struct proc_dir_entry *proc_i8k;    /* Are we running on an supported laptop? */    if (i8k_probe() != 0) {	return -ENODEV;    }    /* Register the proc entry */    proc_i8k = create_proc_info_entry("i8k", 0, NULL, i8k_get_info);    if (!proc_i8k) {	return -ENOENT;    }    proc_i8k->proc_fops = &i8k_fops;    SET_MODULE_OWNER(proc_i8k);    printk(KERN_INFO	   "Dell laptop SMM driver v%s Massimo Dal Zotto (dz@debian.org)\n",	   I8K_VERSION);    return 0;}#ifdef MODULEint init_module(void){    return i8k_init();}void cleanup_module(void){    /* Remove the proc entry */    remove_proc_entry("i8k", NULL);    printk(KERN_INFO "i8k: module unloaded\n");}#endif/* end of file */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -