hwmon: (dell-smm) Restrict fan control and serial number to CAP_SYS_ADMIN by default
[pandora-kernel.git] / drivers / char / i8k.c
1 /*
2  * i8k.c -- Linux driver for accessing the SMM BIOS on Dell laptops.
3  *          See http://www.debian.org/~dz/i8k/ for more information
4  *          and for latest version of this driver.
5  *
6  * Copyright (C) 2001  Massimo Dal Zotto <dz@debian.org>
7  *
8  * Hwmon integration:
9  * Copyright (C) 2011  Jean Delvare <khali@linux-fr.org>
10  *
11  * This program is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU General Public License as published by the
13  * Free Software Foundation; either version 2, or (at your option) any
14  * later version.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  */
21
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/init.h>
25 #include <linux/proc_fs.h>
26 #include <linux/seq_file.h>
27 #include <linux/dmi.h>
28 #include <linux/capability.h>
29 #include <linux/mutex.h>
30 #include <linux/hwmon.h>
31 #include <linux/hwmon-sysfs.h>
32 #include <asm/uaccess.h>
33 #include <asm/io.h>
34
35 #include <linux/i8k.h>
36
37 #define I8K_VERSION             "1.14 21/02/2005"
38
39 #define I8K_SMM_FN_STATUS       0x0025
40 #define I8K_SMM_POWER_STATUS    0x0069
41 #define I8K_SMM_SET_FAN         0x01a3
42 #define I8K_SMM_GET_FAN         0x00a3
43 #define I8K_SMM_GET_SPEED       0x02a3
44 #define I8K_SMM_GET_TEMP        0x10a3
45 #define I8K_SMM_GET_DELL_SIG1   0xfea3
46 #define I8K_SMM_GET_DELL_SIG2   0xffa3
47 #define I8K_SMM_BIOS_VERSION    0x00a6
48
49 #define I8K_FAN_MULT            30
50 #define I8K_MAX_TEMP            127
51
52 #define I8K_FN_NONE             0x00
53 #define I8K_FN_UP               0x01
54 #define I8K_FN_DOWN             0x02
55 #define I8K_FN_MUTE             0x04
56 #define I8K_FN_MASK             0x07
57 #define I8K_FN_SHIFT            8
58
59 #define I8K_POWER_AC            0x05
60 #define I8K_POWER_BATTERY       0x01
61
62 #define I8K_TEMPERATURE_BUG     1
63
64 static DEFINE_MUTEX(i8k_mutex);
65 static char bios_version[4];
66 static char bios_machineid[16];
67 static struct device *i8k_hwmon_dev;
68
69 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
70 MODULE_DESCRIPTION("Driver for accessing SMM BIOS on Dell laptops");
71 MODULE_LICENSE("GPL");
72
73 static int force;
74 module_param(force, bool, 0);
75 MODULE_PARM_DESC(force, "Force loading without checking for supported models");
76
77 static int ignore_dmi;
78 module_param(ignore_dmi, bool, 0);
79 MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
80
81 static int restricted = true;
82 module_param(restricted, bool, 0);
83 MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
84
85 static int power_status;
86 module_param(power_status, bool, 0600);
87 MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
88
89 static int fan_mult = I8K_FAN_MULT;
90 module_param(fan_mult, int, 0);
91 MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with");
92
93 static int i8k_open_fs(struct inode *inode, struct file *file);
94 static long i8k_ioctl(struct file *, unsigned int, unsigned long);
95
96 static const struct file_operations i8k_fops = {
97         .owner          = THIS_MODULE,
98         .open           = i8k_open_fs,
99         .read           = seq_read,
100         .llseek         = seq_lseek,
101         .release        = single_release,
102         .unlocked_ioctl = i8k_ioctl,
103 };
104
105 struct smm_regs {
106         unsigned int eax;
107         unsigned int ebx __attribute__ ((packed));
108         unsigned int ecx __attribute__ ((packed));
109         unsigned int edx __attribute__ ((packed));
110         unsigned int esi __attribute__ ((packed));
111         unsigned int edi __attribute__ ((packed));
112 };
113
114 static inline const char *i8k_get_dmi_data(int field)
115 {
116         const char *dmi_data = dmi_get_system_info(field);
117
118         return dmi_data && *dmi_data ? dmi_data : "?";
119 }
120
121 /*
122  * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
123  */
124 static int i8k_smm(struct smm_regs *regs)
125 {
126         int rc;
127         int eax = regs->eax;
128
129 #if defined(CONFIG_X86_64)
130         asm volatile("pushq %%rax\n\t"
131                 "movl 0(%%rax),%%edx\n\t"
132                 "pushq %%rdx\n\t"
133                 "movl 4(%%rax),%%ebx\n\t"
134                 "movl 8(%%rax),%%ecx\n\t"
135                 "movl 12(%%rax),%%edx\n\t"
136                 "movl 16(%%rax),%%esi\n\t"
137                 "movl 20(%%rax),%%edi\n\t"
138                 "popq %%rax\n\t"
139                 "out %%al,$0xb2\n\t"
140                 "out %%al,$0x84\n\t"
141                 "xchgq %%rax,(%%rsp)\n\t"
142                 "movl %%ebx,4(%%rax)\n\t"
143                 "movl %%ecx,8(%%rax)\n\t"
144                 "movl %%edx,12(%%rax)\n\t"
145                 "movl %%esi,16(%%rax)\n\t"
146                 "movl %%edi,20(%%rax)\n\t"
147                 "popq %%rdx\n\t"
148                 "movl %%edx,0(%%rax)\n\t"
149                 "pushfq\n\t"
150                 "popq %%rax\n\t"
151                 "andl $1,%%eax\n"
152                 :"=a"(rc)
153                 :    "a"(regs)
154                 :    "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
155 #else
156         asm volatile("pushl %%eax\n\t"
157             "movl 0(%%eax),%%edx\n\t"
158             "push %%edx\n\t"
159             "movl 4(%%eax),%%ebx\n\t"
160             "movl 8(%%eax),%%ecx\n\t"
161             "movl 12(%%eax),%%edx\n\t"
162             "movl 16(%%eax),%%esi\n\t"
163             "movl 20(%%eax),%%edi\n\t"
164             "popl %%eax\n\t"
165             "out %%al,$0xb2\n\t"
166             "out %%al,$0x84\n\t"
167             "xchgl %%eax,(%%esp)\n\t"
168             "movl %%ebx,4(%%eax)\n\t"
169             "movl %%ecx,8(%%eax)\n\t"
170             "movl %%edx,12(%%eax)\n\t"
171             "movl %%esi,16(%%eax)\n\t"
172             "movl %%edi,20(%%eax)\n\t"
173             "popl %%edx\n\t"
174             "movl %%edx,0(%%eax)\n\t"
175             "lahf\n\t"
176             "shrl $8,%%eax\n\t"
177             "andl $1,%%eax\n"
178             :"=a"(rc)
179             :    "a"(regs)
180             :    "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
181 #endif
182         if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
183                 return -EINVAL;
184
185         return 0;
186 }
187
188 /*
189  * Read the bios version. Return the version as an integer corresponding
190  * to the ascii value, for example "A17" is returned as 0x00413137.
191  */
192 static int i8k_get_bios_version(void)
193 {
194         struct smm_regs regs = { .eax = I8K_SMM_BIOS_VERSION, };
195
196         return i8k_smm(&regs) ? : regs.eax;
197 }
198
199 /*
200  * Read the Fn key status.
201  */
202 static int i8k_get_fn_status(void)
203 {
204         struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
205         int rc;
206
207         if ((rc = i8k_smm(&regs)) < 0)
208                 return rc;
209
210         switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
211         case I8K_FN_UP:
212                 return I8K_VOL_UP;
213         case I8K_FN_DOWN:
214                 return I8K_VOL_DOWN;
215         case I8K_FN_MUTE:
216                 return I8K_VOL_MUTE;
217         default:
218                 return 0;
219         }
220 }
221
222 /*
223  * Read the power status.
224  */
225 static int i8k_get_power_status(void)
226 {
227         struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
228         int rc;
229
230         if ((rc = i8k_smm(&regs)) < 0)
231                 return rc;
232
233         return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
234 }
235
236 /*
237  * Read the fan status.
238  */
239 static int i8k_get_fan_status(int fan)
240 {
241         struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
242
243         regs.ebx = fan & 0xff;
244         return i8k_smm(&regs) ? : regs.eax & 0xff;
245 }
246
247 /*
248  * Read the fan speed in RPM.
249  */
250 static int i8k_get_fan_speed(int fan)
251 {
252         struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
253
254         regs.ebx = fan & 0xff;
255         return i8k_smm(&regs) ? : (regs.eax & 0xffff) * fan_mult;
256 }
257
258 /*
259  * Set the fan speed (off, low, high). Returns the new fan status.
260  */
261 static int i8k_set_fan(int fan, int speed)
262 {
263         struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
264
265         speed = (speed < 0) ? 0 : ((speed > I8K_FAN_MAX) ? I8K_FAN_MAX : speed);
266         regs.ebx = (fan & 0xff) | (speed << 8);
267
268         return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
269 }
270
271 /*
272  * Read the cpu temperature.
273  */
274 static int i8k_get_temp(int sensor)
275 {
276         struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, };
277         int rc;
278         int temp;
279
280 #ifdef I8K_TEMPERATURE_BUG
281         static int prev;
282 #endif
283         regs.ebx = sensor & 0xff;
284         if ((rc = i8k_smm(&regs)) < 0)
285                 return rc;
286
287         temp = regs.eax & 0xff;
288
289 #ifdef I8K_TEMPERATURE_BUG
290         /*
291          * Sometimes the temperature sensor returns 0x99, which is out of range.
292          * In this case we return (once) the previous cached value. For example:
293          # 1003655137 00000058 00005a4b
294          # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
295          # 1003655139 00000054 00005c52
296          */
297         if (temp > I8K_MAX_TEMP) {
298                 temp = prev;
299                 prev = I8K_MAX_TEMP;
300         } else {
301                 prev = temp;
302         }
303 #endif
304
305         return temp;
306 }
307
308 static int i8k_get_dell_signature(int req_fn)
309 {
310         struct smm_regs regs = { .eax = req_fn, };
311         int rc;
312
313         if ((rc = i8k_smm(&regs)) < 0)
314                 return rc;
315
316         return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
317 }
318
319 static int
320 i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
321 {
322         int val = 0;
323         int speed;
324         unsigned char buff[16];
325         int __user *argp = (int __user *)arg;
326
327         if (!argp)
328                 return -EINVAL;
329
330         switch (cmd) {
331         case I8K_BIOS_VERSION:
332                 val = i8k_get_bios_version();
333                 break;
334
335         case I8K_MACHINE_ID:
336                 if (restricted && !capable(CAP_SYS_ADMIN))
337                         return -EPERM;
338
339                 memset(buff, 0, sizeof(buff));
340                 strlcpy(buff, bios_machineid, sizeof(buff));
341                 break;
342
343         case I8K_FN_STATUS:
344                 val = i8k_get_fn_status();
345                 break;
346
347         case I8K_POWER_STATUS:
348                 val = i8k_get_power_status();
349                 break;
350
351         case I8K_GET_TEMP:
352                 val = i8k_get_temp(0);
353                 break;
354
355         case I8K_GET_SPEED:
356                 if (copy_from_user(&val, argp, sizeof(int)))
357                         return -EFAULT;
358
359                 val = i8k_get_fan_speed(val);
360                 break;
361
362         case I8K_GET_FAN:
363                 if (copy_from_user(&val, argp, sizeof(int)))
364                         return -EFAULT;
365
366                 val = i8k_get_fan_status(val);
367                 break;
368
369         case I8K_SET_FAN:
370                 if (restricted && !capable(CAP_SYS_ADMIN))
371                         return -EPERM;
372
373                 if (copy_from_user(&val, argp, sizeof(int)))
374                         return -EFAULT;
375
376                 if (copy_from_user(&speed, argp + 1, sizeof(int)))
377                         return -EFAULT;
378
379                 val = i8k_set_fan(val, speed);
380                 break;
381
382         default:
383                 return -EINVAL;
384         }
385
386         if (val < 0)
387                 return val;
388
389         switch (cmd) {
390         case I8K_BIOS_VERSION:
391                 if (copy_to_user(argp, &val, 4))
392                         return -EFAULT;
393
394                 break;
395         case I8K_MACHINE_ID:
396                 if (copy_to_user(argp, buff, 16))
397                         return -EFAULT;
398
399                 break;
400         default:
401                 if (copy_to_user(argp, &val, sizeof(int)))
402                         return -EFAULT;
403
404                 break;
405         }
406
407         return 0;
408 }
409
410 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
411 {
412         long ret;
413
414         mutex_lock(&i8k_mutex);
415         ret = i8k_ioctl_unlocked(fp, cmd, arg);
416         mutex_unlock(&i8k_mutex);
417
418         return ret;
419 }
420
421 /*
422  * Print the information for /proc/i8k.
423  */
424 static int i8k_proc_show(struct seq_file *seq, void *offset)
425 {
426         int fn_key, cpu_temp, ac_power;
427         int left_fan, right_fan, left_speed, right_speed;
428
429         cpu_temp        = i8k_get_temp(0);                      /* 11100 µs */
430         left_fan        = i8k_get_fan_status(I8K_FAN_LEFT);     /*   580 µs */
431         right_fan       = i8k_get_fan_status(I8K_FAN_RIGHT);    /*   580 µs */
432         left_speed      = i8k_get_fan_speed(I8K_FAN_LEFT);      /*   580 µs */
433         right_speed     = i8k_get_fan_speed(I8K_FAN_RIGHT);     /*   580 µs */
434         fn_key          = i8k_get_fn_status();                  /*   750 µs */
435         if (power_status)
436                 ac_power = i8k_get_power_status();              /* 14700 µs */
437         else
438                 ac_power = -1;
439
440         /*
441          * Info:
442          *
443          * 1)  Format version (this will change if format changes)
444          * 2)  BIOS version
445          * 3)  BIOS machine ID
446          * 4)  Cpu temperature
447          * 5)  Left fan status
448          * 6)  Right fan status
449          * 7)  Left fan speed
450          * 8)  Right fan speed
451          * 9)  AC power
452          * 10) Fn Key status
453          */
454         return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
455                           I8K_PROC_FMT,
456                           bios_version,
457                           (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid,
458                           cpu_temp,
459                           left_fan, right_fan, left_speed, right_speed,
460                           ac_power, fn_key);
461 }
462
463 static int i8k_open_fs(struct inode *inode, struct file *file)
464 {
465         return single_open(file, i8k_proc_show, NULL);
466 }
467
468
469 /*
470  * Hwmon interface
471  */
472
473 static ssize_t i8k_hwmon_show_temp(struct device *dev,
474                                    struct device_attribute *devattr,
475                                    char *buf)
476 {
477         int cpu_temp;
478
479         cpu_temp = i8k_get_temp(0);
480         if (cpu_temp < 0)
481                 return cpu_temp;
482         return sprintf(buf, "%d\n", cpu_temp * 1000);
483 }
484
485 static ssize_t i8k_hwmon_show_fan(struct device *dev,
486                                   struct device_attribute *devattr,
487                                   char *buf)
488 {
489         int index = to_sensor_dev_attr(devattr)->index;
490         int fan_speed;
491
492         fan_speed = i8k_get_fan_speed(index);
493         if (fan_speed < 0)
494                 return fan_speed;
495         return sprintf(buf, "%d\n", fan_speed);
496 }
497
498 static ssize_t i8k_hwmon_show_label(struct device *dev,
499                                     struct device_attribute *devattr,
500                                     char *buf)
501 {
502         static const char *labels[4] = {
503                 "i8k",
504                 "CPU",
505                 "Left Fan",
506                 "Right Fan",
507         };
508         int index = to_sensor_dev_attr(devattr)->index;
509
510         return sprintf(buf, "%s\n", labels[index]);
511 }
512
513 static DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL);
514 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
515                           I8K_FAN_LEFT);
516 static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
517                           I8K_FAN_RIGHT);
518 static SENSOR_DEVICE_ATTR(name, S_IRUGO, i8k_hwmon_show_label, NULL, 0);
519 static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 1);
520 static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 2);
521 static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_label, NULL, 3);
522
523 static void i8k_hwmon_remove_files(struct device *dev)
524 {
525         device_remove_file(dev, &dev_attr_temp1_input);
526         device_remove_file(dev, &sensor_dev_attr_fan1_input.dev_attr);
527         device_remove_file(dev, &sensor_dev_attr_fan2_input.dev_attr);
528         device_remove_file(dev, &sensor_dev_attr_temp1_label.dev_attr);
529         device_remove_file(dev, &sensor_dev_attr_fan1_label.dev_attr);
530         device_remove_file(dev, &sensor_dev_attr_fan2_label.dev_attr);
531         device_remove_file(dev, &sensor_dev_attr_name.dev_attr);
532 }
533
534 static int __init i8k_init_hwmon(void)
535 {
536         int err;
537
538         i8k_hwmon_dev = hwmon_device_register(NULL);
539         if (IS_ERR(i8k_hwmon_dev)) {
540                 err = PTR_ERR(i8k_hwmon_dev);
541                 i8k_hwmon_dev = NULL;
542                 printk(KERN_ERR "i8k: hwmon registration failed (%d)\n", err);
543                 return err;
544         }
545
546         /* Required name attribute */
547         err = device_create_file(i8k_hwmon_dev,
548                                  &sensor_dev_attr_name.dev_attr);
549         if (err)
550                 goto exit_unregister;
551
552         /* CPU temperature attributes, if temperature reading is OK */
553         err = i8k_get_temp(0);
554         if (err < 0) {
555                 dev_dbg(i8k_hwmon_dev,
556                         "Not creating temperature attributes (%d)\n", err);
557         } else {
558                 err = device_create_file(i8k_hwmon_dev, &dev_attr_temp1_input);
559                 if (err)
560                         goto exit_remove_files;
561                 err = device_create_file(i8k_hwmon_dev,
562                                          &sensor_dev_attr_temp1_label.dev_attr);
563                 if (err)
564                         goto exit_remove_files;
565         }
566
567         /* Left fan attributes, if left fan is present */
568         err = i8k_get_fan_status(I8K_FAN_LEFT);
569         if (err < 0) {
570                 dev_dbg(i8k_hwmon_dev,
571                         "Not creating %s fan attributes (%d)\n", "left", err);
572         } else {
573                 err = device_create_file(i8k_hwmon_dev,
574                                          &sensor_dev_attr_fan1_input.dev_attr);
575                 if (err)
576                         goto exit_remove_files;
577                 err = device_create_file(i8k_hwmon_dev,
578                                          &sensor_dev_attr_fan1_label.dev_attr);
579                 if (err)
580                         goto exit_remove_files;
581         }
582
583         /* Right fan attributes, if right fan is present */
584         err = i8k_get_fan_status(I8K_FAN_RIGHT);
585         if (err < 0) {
586                 dev_dbg(i8k_hwmon_dev,
587                         "Not creating %s fan attributes (%d)\n", "right", err);
588         } else {
589                 err = device_create_file(i8k_hwmon_dev,
590                                          &sensor_dev_attr_fan2_input.dev_attr);
591                 if (err)
592                         goto exit_remove_files;
593                 err = device_create_file(i8k_hwmon_dev,
594                                          &sensor_dev_attr_fan2_label.dev_attr);
595                 if (err)
596                         goto exit_remove_files;
597         }
598
599         return 0;
600
601  exit_remove_files:
602         i8k_hwmon_remove_files(i8k_hwmon_dev);
603  exit_unregister:
604         hwmon_device_unregister(i8k_hwmon_dev);
605         return err;
606 }
607
608 static void __exit i8k_exit_hwmon(void)
609 {
610         i8k_hwmon_remove_files(i8k_hwmon_dev);
611         hwmon_device_unregister(i8k_hwmon_dev);
612 }
613
614 static struct dmi_system_id __initdata i8k_dmi_table[] = {
615         {
616                 .ident = "Dell Inspiron",
617                 .matches = {
618                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
619                         DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
620                 },
621         },
622         {
623                 .ident = "Dell Latitude",
624                 .matches = {
625                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
626                         DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
627                 },
628         },
629         {
630                 .ident = "Dell Inspiron 2",
631                 .matches = {
632                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
633                         DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
634                 },
635         },
636         {
637                 .ident = "Dell Latitude 2",
638                 .matches = {
639                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
640                         DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
641                 },
642         },
643         {       /* UK Inspiron 6400  */
644                 .ident = "Dell Inspiron 3",
645                 .matches = {
646                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
647                         DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
648                 },
649         },
650         {
651                 .ident = "Dell Inspiron 3",
652                 .matches = {
653                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
654                         DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
655                 },
656         },
657         {
658                 .ident = "Dell Precision",
659                 .matches = {
660                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
661                         DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
662                 },
663         },
664         {
665                 .ident = "Dell Vostro",
666                 .matches = {
667                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
668                         DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
669                 },
670         },
671         {
672                 .ident = "Dell XPS421",
673                 .matches = {
674                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
675                         DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
676                 },
677         },
678         { }
679 };
680
681 /*
682  * Probe for the presence of a supported laptop.
683  */
684 static int __init i8k_probe(void)
685 {
686         char buff[4];
687         int version;
688
689         /*
690          * Get DMI information
691          */
692         if (!dmi_check_system(i8k_dmi_table)) {
693                 if (!ignore_dmi && !force)
694                         return -ENODEV;
695
696                 printk(KERN_INFO "i8k: not running on a supported Dell system.\n");
697                 printk(KERN_INFO "i8k: vendor=%s, model=%s, version=%s\n",
698                         i8k_get_dmi_data(DMI_SYS_VENDOR),
699                         i8k_get_dmi_data(DMI_PRODUCT_NAME),
700                         i8k_get_dmi_data(DMI_BIOS_VERSION));
701         }
702
703         strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), sizeof(bios_version));
704         strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
705                 sizeof(bios_machineid));
706
707         /*
708          * Get SMM Dell signature
709          */
710         if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
711             i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
712                 printk(KERN_ERR "i8k: unable to get SMM Dell signature\n");
713                 if (!force)
714                         return -ENODEV;
715         }
716
717         /*
718          * Get SMM BIOS version.
719          */
720         version = i8k_get_bios_version();
721         if (version <= 0) {
722                 printk(KERN_WARNING "i8k: unable to get SMM BIOS version\n");
723         } else {
724                 buff[0] = (version >> 16) & 0xff;
725                 buff[1] = (version >> 8) & 0xff;
726                 buff[2] = (version) & 0xff;
727                 buff[3] = '\0';
728                 /*
729                  * If DMI BIOS version is unknown use SMM BIOS version.
730                  */
731                 if (!dmi_get_system_info(DMI_BIOS_VERSION))
732                         strlcpy(bios_version, buff, sizeof(bios_version));
733
734                 /*
735                  * Check if the two versions match.
736                  */
737                 if (strncmp(buff, bios_version, sizeof(bios_version)) != 0)
738                         printk(KERN_WARNING "i8k: BIOS version mismatch: %s != %s\n",
739                                 buff, bios_version);
740         }
741
742         return 0;
743 }
744
745 static int __init i8k_init(void)
746 {
747         struct proc_dir_entry *proc_i8k;
748         int err;
749
750         /* Are we running on an supported laptop? */
751         if (i8k_probe())
752                 return -ENODEV;
753
754         /* Register the proc entry */
755         proc_i8k = proc_create("i8k", 0, NULL, &i8k_fops);
756         if (!proc_i8k)
757                 return -ENOENT;
758
759         err = i8k_init_hwmon();
760         if (err)
761                 goto exit_remove_proc;
762
763         printk(KERN_INFO
764                "Dell laptop SMM driver v%s Massimo Dal Zotto (dz@debian.org)\n",
765                I8K_VERSION);
766
767         return 0;
768
769  exit_remove_proc:
770         remove_proc_entry("i8k", NULL);
771         return err;
772 }
773
774 static void __exit i8k_exit(void)
775 {
776         i8k_exit_hwmon();
777         remove_proc_entry("i8k", NULL);
778 }
779
780 module_init(i8k_init);
781 module_exit(i8k_exit);